> For the complete documentation index, see [llms.txt](https://calctree.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calctree.gitbook.io/docs/calculations/creating-calculations/maths-equations/native-functions/utility-functions.md).

# Utility functions

CalcTree includes several utility functions to help you inspect, validate, or manipulate values. These are especially useful for:

* Input validation
* Conditional logic
* Type checking
* Ensuring numerical stability in custom calculations

### Type & Property Checks

| Function        | Description                      | CalcTree Example             |
| --------------- | -------------------------------- | ---------------------------- |
| `isNaN(x)`      | Check if value is NaN            | `isNaN(0/0)` → `true`        |
| `isZero(x)`     | Check if value is exactly zero   | `isZero(0)` → `true`         |
| `isPositive(x)` | Check if value > 0               | `isPositive(10)` → `true`    |
| `isNegative(x)` | Check if value < 0               | `isNegative(-5)` → `true`    |
| `isInteger(x)`  | Check if value is an integer     | `isInteger(2.0)` → `true`    |
| `isNumeric(x)`  | Check if value is number or unit | `isNumeric("abc")` → `false` |

### Type Introspection

| Function    | Description                   | CalcTree Example           |
| ----------- | ----------------------------- | -------------------------- |
| `typeOf(x)` | Return the type as a string   | `typeOf(3)` → `"number"`   |
| `clone(x)`  | Return a deep copy of a value | `clone([1, 2])` → `[1, 2]` |

### Numeric Conversion

| Function     | Description                           | CalcTree Example     |
| ------------ | ------------------------------------- | -------------------- |
| `numeric(x)` | Convert value to number (if possible) | `numeric("5")` → `5` |

### Notes for CalcTree

* Use these functions inside conditionals or `if`-style formulas to make your pages more robust.
* `typeOf()` can help debug input types from tables or imported files.
* `isNaN()` is particularly useful when handling optional or calculated fields that may not resolve.

{% hint style="info" %}
📘 **Looking for more functions?**\
CalcTree’s expression engine is powered by [MathJS](https://mathjs.org/docs/reference/functions.html).\
For a full list of available functions, visit the [MathJS Function Reference](https://mathjs.org/docs/reference/functions.html).\
Most functions listed there are supported in CalcTree unless otherwise noted.
{% endhint %}
