FloatCompare
Description
Compare a float against another numeric value. Dispatches on the type of rhs to the matching internal handler.
Parameters
| Name | Direction | Description |
|---|---|---|
lhs |
in | Left-hand float |
rhs |
in | Right-hand operand (Float, Int, pointer, integer, or native float type) |
error |
out | Optional error flag set to true on operational failure and false otherwise. |
Usage example (from documentation)
int cmp = FloatCompare(&value, 1.5);Success
Returns -1 if lhs < rhs, 0 if equal, 1 if lhs > rhs.
Failure
Returns 0 when an intermediate conversion of rhs to Float fails. With the two-argument form a failure result is indistinguishable from a true equality; with the three-argument form *error is set to true.
Usage example (Cross-references)
Usage examples (Cross-references)
bool test_float_compare_small_small(void) {
WriteFmt("Testing FloatCompare with small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit(); Float c = FloatFromStr("-1.23", &alloc.base);
bool result = FloatCompare(&a, &b) == 0;
result = result && FloatEQ(&a, &b);
result = result && (FloatCompare(&c, &a) < 0); bool result = FloatCompare(&a, &b) == 0;
result = result && FloatEQ(&a, &b);
result = result && (FloatCompare(&c, &a) < 0);
result = result && (FloatCompare(&a, &c) > 0); result = result && FloatEQ(&a, &b);
result = result && (FloatCompare(&c, &a) < 0);
result = result && (FloatCompare(&a, &c) > 0);
FloatDeinit(&a);
bool test_float_compare_very_large_large(void) {
WriteFmt("Testing FloatCompare with very large floats\n");
DefaultAllocator alloc = DefaultAllocatorInit(); bool result = FloatLT(&a, &b);
result = result && FloatGT(&b, &a);
result = result && (FloatCompare(&a, &c) == 0);
result = result && FloatEQ(&a, &c);
bool test_float_compare_very_large_small(void) {
WriteFmt("Testing FloatCompare with very large and small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();
bool test_float_compare_generic(void) {
WriteFmt("Testing FloatCompare generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit(); Int next = IntFrom(13, &alloc.base);
bool result = (FloatCompare(&value, &same) == 0);
result = result && (FloatCompare(&value, &whole) > 0);
result = result && (FloatCompare(&value, &next) < 0);
bool result = (FloatCompare(&value, &same) == 0);
result = result && (FloatCompare(&value, &whole) > 0);
result = result && (FloatCompare(&value, &next) < 0);
result = result && (FloatCompare(&value, 12) > 0); bool result = (FloatCompare(&value, &same) == 0);
result = result && (FloatCompare(&value, &whole) > 0);
result = result && (FloatCompare(&value, &next) < 0);
result = result && (FloatCompare(&value, 12) > 0);
result = result && (FloatCompare(&value, -1) > 0); result = result && (FloatCompare(&value, &whole) > 0);
result = result && (FloatCompare(&value, &next) < 0);
result = result && (FloatCompare(&value, 12) > 0);
result = result && (FloatCompare(&value, -1) > 0);
result = result && (FloatCompare(&value, 12.5f) == 0); result = result && (FloatCompare(&value, &next) < 0);
result = result && (FloatCompare(&value, 12) > 0);
result = result && (FloatCompare(&value, -1) > 0);
result = result && (FloatCompare(&value, 12.5f) == 0);
result = result && (FloatCompare(&value, 12.5) == 0); result = result && (FloatCompare(&value, 12) > 0);
result = result && (FloatCompare(&value, -1) > 0);
result = result && (FloatCompare(&value, 12.5f) == 0);
result = result && (FloatCompare(&value, 12.5) == 0);
result = result && FloatEQ(&value, &same); result = result && (FloatCompare(&value, -1) > 0);
result = result && (FloatCompare(&value, 12.5f) == 0);
result = result && (FloatCompare(&value, 12.5) == 0);
result = result && FloatEQ(&value, &same);
result = result && FloatEQ(&value, 12.5);
Last updated on