Perform a comparison on two XFL floating point numbers

Concepts

Behaviour

  • Evaluate a comparison of two XFL floating point numbers
  • Return the result of the comparison as a boolean encoded in an int64_t.

Definition

int64_t float_compare (
    int64_t float1,
    int64_t float2,
    uint32_t mode
);

Example

if (float_compare(pusd_to_send, 0, COMPARE_LESS) == 1)
{
  // pusd_to_send is less than 0
}

Parameters

NameTypeDescription
float1int64_tAn XFL floating point enclosing number representing the first operand to the comparison
float2int64_tAn XFL floating point enclosing number representing the second operand to the comparison
modeuint32_tA bit-flag field consisting of any of (or any logically valid combination of) the following flags:
COMPARE_LESS
COMPARE_EQUAL
COMPARE_GREATER

Valid combinations are:
COMPARE_LESS | COMPARE_GREATER
- Not equal

COMPARE_LESS | COMPARE_EQUAL
- Less than or equal to

COMPARE_GREATER | COMPARE_EQUAL
- Greater than or equal to

🚧

Caution

Always verify the function returned 1 rather than non-zero, as negative error codes will be classed as non-zero.

Return Code

TypeDescription
int64_t0 if the comparison was logically false.
1 if the comparison was logically true.

If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number

INVALID_ARGUMENT
- invalid combination of supplied comparison flags.