---
title: float_set
description: Create a float from an exponent and mantissa
---
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">
* Compute an XFL (xls17) floating point from the provided exponent and mantissa
* Return that XFL as an int64_t
</TabItem>

<TabItem label="JavaScript">
* Sets the exponent and mantissa for a float representation.
* Returns an error code or a new XFL as a bigint.
</TabItem>
</Tabs>



### Definition

<Tabs>
<TabItem label="C">
```c
int64_t float_set (
    int32_t exponent,
    int64_t mantissa
);
```


</TabItem>

<TabItem label="JavaScript">
```javascript
function float_set(exponent: number, mantissa: number): ErrorCode | bigint
```
</TabItem>
</Tabs>



### Example

<Tabs>
<TabItem label="C">
```c
int64_t small_amount =
  float_set(-81, 1);
```


</TabItem>

<TabItem label="JavaScript">
```javascript
const small_amount = float_set(-81, 1);
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">
| Name     | Type     | Description                                                     |
| -------- | -------- | --------------------------------------------------------------- |
| exponent | int32_t | An exponent in the range `-96` to `80`                          |
| mantissa | int64_t | A mantissa. If negative then the sign of the float is negative. |

<Aside type="caution">
When setting a mantissa that is greater or fewer than 16 decimal digits the exponent will be adjusted to ensure the mantissa is exactly 16 digits. This adjustment may result in an `INVALID_FLOAT` in some circumstances.
</Aside>

<Aside type="tip" title="Special case">
XFL canonical 0 is also 0 in the enclosing number. Thus there is never a need to call `float_set(0,0);`
</Aside>
</TabItem>

<TabItem label="JavaScript">


| Name     | Type   | Description                                                     |
| -------- | ------ | --------------------------------------------------------------- |
| exponent | bigint | An exponent in the range `-96` to `80`                          |
| mantissa | bigint | A mantissa. If negative then the sign of the float is negative. |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">
| Type     | Description                                                                                                                                                                         |
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int64_t | <p>The XFL (xls17) enclosing number<br /><br />If negative, an error:<br /><code>INVALID_FLOAT</code><br />- The adjustment of the mantissa to 16 digits produced an under or overflow.</p> |


</TabItem>

<TabItem label="JavaScript">


| Type                | Description                                        |
| ------------------- | -------------------------------------------------- |
| ErrorCode \| bigint | An error code or the XFL (xls17) enclosing number. |
</TabItem>
</Tabs>

