Skip to content
FloatIsNegative

FloatIsNegative

FloatIsNegative

Description

Test whether a floating-point value is negative.

Parameters

Name Direction Description
value in Float to test

Usage example (from documentation)

  bool negative = FloatIsNegative(&value);

Returns

true when the value is non-zero and has a negative sign.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool FloatIsNegative(Float *value) {
        ValidateFloat(value);
        return !FloatIsZero(value) && value->negative;
        ValidateFloat(value);
    
        if (FloatIsNegative(value)) {
            IntDeinit(&temp);
            return false;
            return 0;
        }
        if (FloatIsNegative(lhs) != FloatIsNegative(rhs)) {
            return FloatIsNegative(lhs) ? -1 : 1;
        }
        }
        if (FloatIsNegative(lhs) != FloatIsNegative(rhs)) {
            return FloatIsNegative(lhs) ? -1 : 1;
        }
    
        cmp = float_abs_compare(lhs, rhs);
        return FloatIsNegative(lhs) ? -cmp : cmp;
    }
    
        IntMul(&temp.significand, &a->significand, &b->significand);
        temp.negative = FloatIsNegative(a) != FloatIsNegative(b);
        temp.exponent = float_add_i64_checked(a->exponent, b->exponent);
        IntDiv(&temp.significand, &scaled, &b->significand);
    
        temp.negative = FloatIsNegative(a) != FloatIsNegative(b);
        temp.exponent = float_sub_i64_checked(float_sub_i64_checked(a->exponent, b->exponent), (i64)precision);
    
        bool result = strcmp(text.data, "42") == 0;
        result      = result && !FloatIsNegative(&value);
    
        StrDeinit(&text);
    
        bool result = strcmp(text.data, "-42") == 0;
        result      = result && FloatIsNegative(&value);
    
        StrDeinit(&text);
    
    bool test_float_is_negative(void) {
        WriteFmt("Testing FloatIsNegative\n");
    
        Float neg  = FloatFromStr("-42");
        Float zero = FloatFromStr("-0.0");
    
        bool result = FloatIsNegative(&neg);
        result      = result && !FloatIsNegative(&pos);
        result      = result && !FloatIsNegative(&zero);
    
        bool result = FloatIsNegative(&neg);
        result      = result && !FloatIsNegative(&pos);
        result      = result && !FloatIsNegative(&zero);
        bool result = FloatIsNegative(&neg);
        result      = result && !FloatIsNegative(&pos);
        result      = result && !FloatIsNegative(&zero);
    
        FloatDeinit(&neg);
    
        bool result = FloatIsZero(&value);
        result      = result && !FloatIsNegative(&value);
        result      = result && (FloatExponent(&value) == 0);
    
        bool result = FloatIsZero(&value);
        result      = result && !FloatIsNegative(&value);
        result      = result && (FloatExponent(&value) == 0);
Last updated on