---
title: float_compare
description: Perform a comparison on two XFL floating point numbers
---
import { Tabs, TabItem, LinkButton, Aside } from '@astrojs/starlight/components';

### Concepts

<LinkButton href="/docs/hooks/concepts/floating-point-numbers-xfl">Floating Point Numbers (XFL)</LinkButton>

### Behaviour

<Tabs>
<TabItem label="C">
* Evaluate a comparison of two XFL floating point numbers
* Return the result of the comparison as a boolean encoded in an int64_t.
</TabItem>

<TabItem label="JavaScript">
* Evaluate a comparison of two XFL floating point numbers
* Returns an error code or the comparison result as a number.
</TabItem>
</Tabs>



### Definition

<Tabs>
<TabItem label="C">
```c
int64_t float_compare (
    int64_t float1,
    int64_t float2,
    uint32_t mode
);
```
</TabItem>

<TabItem label="JavaScript">
```javascript
function float_compare(
    f1: bigint,
    f2: bigint,
    mode: number
  ): ErrorCode | number
```
</TabItem>
</Tabs>



### Example

<Tabs>
<TabItem label="C">
```c
if (float_compare(pusd_to_send, 0, COMPARE_LESS) == 1)
{
  // pusd_to_send is less than 0
}
```


</TabItem>

<TabItem label="JavaScript">
```javascript
if (float_compare(pusd_to_send, 0n, COMPARE_LESS) == 1)
{
  // pusd_to_send is less than 0
}
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">


| Name   | Type      | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| float1 | int64_t  | An XFL floating point enclosing number representing the first operand to the comparison                                                                                                                                                                                                                                                                                                                                                                                                                |
| float2 | int64_t  | An XFL floating point enclosing number representing the second operand to the comparison                                                                                                                                                                                                                                                                                                                                                                                                               |
| mode   | uint32_t | A bit-flag field consisting of any of (or any logically valid combination of) the following flags:<br /><code>COMPARE_EQUAL</code> `1`<br /><code>COMPARE_LESS</code> `2`<br /><code>COMPARE_GREATER</code> `4`<br /><br />Valid combinations are:<br /><code>COMPARE_LESS</code> \| <code>COMPARE_GREATER</code><br />- Not equal<br /><br /><code>COMPARE_LESS</code> \| <code>COMPARE_EQUAL</code><br />- Less than or equal to<br /><br /><code>COMPARE_GREATER</code> \| <code>COMPARE_EQUAL</code><br />- Greater than or equal to |

<Aside type="caution">
Always verify the function returned `1` rather than `non-zero`, as negative error codes will be classed as `non-zero`.
</Aside>
</TabItem>

<TabItem label="JavaScript">


| Name | Type   | Description                                                    |
| ---- | ------ | -------------------------------------------------------------- |
| f1   | bigint | The first float to compare.                                    |
| f2   | bigint | The second float to compare.                                   |
| mode | number | The comparison mode (e.g., less than, equal to, greater than). |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">


| Type     | Description                                                                                                                                                                                                                                                                                                                                           |
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int64_t | <code>0</code> if the comparison was logically false.<br /><code>1</code> if the comparison was logically true.<br /><br />If negative, an error:<br /><code>INVALID_FLOAT</code><br />- one of the supplied parameters was not a valid XFL enclosing number<br /><br /><code>INVALID_ARGUMENT</code><br />- invalid combination of supplied comparison flags. |
</TabItem>

<TabItem label="JavaScript">


| Type                | Description                                                 |
| ------------------- | ----------------------------------------------------------- |
| ErrorCode or number | Returns an error code or the comparison result as a number. |
</TabItem>
</Tabs>

