---
title: float_root
description: Compute the nth root of an XFL
---
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 a the `nth` root of an XFL number
* Return the new XFL

<Aside type="caution">
Due to speed constraints,`float_root` converts the argument to an IEEE base-2 double precision floating point before applying n-th root. Therefore the returned result will often contain less precision than expected. If you need better precision you should consider dividing your XFL into a high and a low product then individually take the square roots of those products and multiply the results together.
</Aside>
</TabItem>

<TabItem label="JavaScript">
* Calculates the nth root of a float representation.
* An error code or the resulting root as a bigint.
</TabItem>
</Tabs>



### Definition

<Tabs>
<TabItem label="C">
```c
int64_t float_root (
    int64_t float1,
    uint32_t n
);
```


</TabItem>

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



### Example

<Tabs>
<TabItem label="C">
```c
int64_t three =
    float_root(nine, 2);
```

<Aside type="caution">
If a negative number is passed the function will return `COMPLEX_NOT_SUPPORTED` if the root is an even root.
</Aside>
</TabItem>

<TabItem label="JavaScript">
```javascript
const three =
  float_root(nine, 2)
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">
| Name   | Type      | Description                                                                                              |
| ------ | --------- | -------------------------------------------------------------------------------------------------------- |
| float1 | int64_t  | An XFL floating point enclosing number representing the floating point number to take the square root of |
| n      | uint32_t | The root to compute, for example `2` is a square root.                                                   |
</TabItem>

<TabItem label="JavaScript">
| Name | Type   | Description                          |
| ---- | ------ | ------------------------------------ |
| f1   | bigint | The float to calculate the root of.  |
| n    | number | The degree of the root to calculate. |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">


| Type     | Description                                                                                                                                                                                                                                                                                 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int64_t | <p>The computed nth root<br /><br />If negative, an error:<br /><code>INVALID_FLOAT</code><br />- the supplied parameter was not a valid XFL enclosing number<br /><br /><code>COMPLEX_NOT_SUPPORTED</code><br />- the supplied parameter was a negative number which would result in a complex root.</p> |
</TabItem>

<TabItem label="JavaScript">


| Type                | Description                                              |
| ------------------- | -------------------------------------------------------- |
| bigint or ErrorCode | Returns an error code or the resulting root as a bigint. |
</TabItem>
</Tabs>

