> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kayanos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Math helpers

> Every registered numeric helper, with signatures and examples for calculated fields and rules.

## When to use these helpers

Use these helpers to total values, compare thresholds, round outputs, and calculate ratios. They are registered as functions and transforms.

## Calling style

Call a helper as `round($.requested_amount, 2)`. Not every helper is available everywhere: validation, form, and document-template helpers have distinct context contracts. Editor suggestions are not proof that a helper is supported at runtime.

## Complete function reference

### `abs`

Returns the absolute value of a number

**Signature:** `abs(x)`

**Example:**

```txt theme={null}
abs(-5) // 5
```

**Note:** It can also be written as a transform when the first value is the input: `value | abs(...)`.

### `acos`

Returns the arccosine of a number

**Signature:** `acos(x)`

**Example:**

```txt theme={null}
acos(1) // 0
```

**Note:** It can also be written as a transform when the first value is the input: `value | acos(...)`.

### `asin`

Returns the arcsine of a number

**Signature:** `asin(x)`

**Example:**

```txt theme={null}
asin(0) // 0
```

**Note:** It can also be written as a transform when the first value is the input: `value | asin(...)`.

### `atan`

Returns the arctangent of a number

**Signature:** `atan(x)`

**Example:**

```txt theme={null}
atan(0) // 0
```

**Note:** It can also be written as a transform when the first value is the input: `value | atan(...)`.

### `atan2`

Returns the arctangent of the quotient of its arguments

**Signature:** `atan2(y, x)`

**Example:**

```txt theme={null}
atan2(1, 1) // Math.PI / 4
```

**Note:** It can also be written as a transform when the first value is the input: `value | atan2(...)`.

### `avg`

Returns the average of all arguments

**Signature:** `avg(...values)`

**Example:**

```txt theme={null}
avg(1, 2, 3) // 2
```

**Note:** It can also be written as a transform when the first value is the input: `value | avg(...)`.

### `cbrt`

Returns the cube root of a number

**Signature:** `cbrt(x)`

**Example:**

```txt theme={null}
cbrt(8) // 2
```

**Note:** It can also be written as a transform when the first value is the input: `value | cbrt(...)`.

### `ceil`

Returns the smallest integer greater than or equal to a number, with optional precision

**Signature:** `ceil(x, precision?)`

**Example:**

```txt theme={null}
ceil(4.21, 1) // 4.3
```

**Note:** It can also be written as a transform when the first value is the input: `value | ceil(...)`.

### `clamp`

Clamps a number between a minimum and maximum value

**Signature:** `clamp(value, min, max)`

**Example:**

```txt theme={null}
clamp(5, 0, 10) // 5
```

**Note:** It can also be written as a transform when the first value is the input: `value | clamp(...)`.

### `cos`

Returns the cosine of a number (in radians)

**Signature:** `cos(x)`

**Example:**

```txt theme={null}
cos(0) // 1
```

**Note:** It can also be written as a transform when the first value is the input: `value | cos(...)`.

### `exp`

Returns e raised to the power of x

**Signature:** `exp(x)`

**Example:**

```txt theme={null}
exp(0) // 1
```

**Note:** It can also be written as a transform when the first value is the input: `value | exp(...)`.

### `factorial`

Calculates the factorial of a number

**Signature:** `factorial(n)`

**Example:**

```txt theme={null}
factorial(5) // 120
```

**Note:** It can also be written as a transform when the first value is the input: `value | factorial(...)`.

### `floor`

Returns the largest integer less than or equal to a number, with optional precision

**Signature:** `floor(x, precision?)`

**Example:**

```txt theme={null}
floor(4.76, 1) // 4.7
```

**Note:** It can also be written as a transform when the first value is the input: `value | floor(...)`.

### `gcd`

Calculates the greatest common divisor of two numbers

**Signature:** `gcd(a, b)`

**Example:**

```txt theme={null}
gcd(48, 18) // 6
```

**Note:** It can also be written as a transform when the first value is the input: `value | gcd(...)`.

### `isPrime`

Checks if a number is prime

**Signature:** `isPrime(n)`

**Example:**

```txt theme={null}
isPrime(5) // true
```

**Note:** It can also be written as a transform when the first value is the input: `value | isPrime(...)`.

### `lcm`

Calculates the least common multiple of two numbers

**Signature:** `lcm(a, b)`

**Example:**

```txt theme={null}
lcm(4, 6) // 12
```

**Note:** It can also be written as a transform when the first value is the input: `value | lcm(...)`.

### `lerp`

Linear interpolation between two values

**Signature:** `lerp(start, end, t)`

**Example:**

```txt theme={null}
lerp(0, 10, 0.5) // 5
```

**Note:** It can also be written as a transform when the first value is the input: `value | lerp(...)`.

### `log`

Returns the natural logarithm of a number

**Signature:** `log(x)`

**Example:**

```txt theme={null}
log(1) // 0
```

**Note:** It can also be written as a transform when the first value is the input: `value | log(...)`.

### `log10`

Returns the base-10 logarithm of a number

**Signature:** `log10(x)`

**Example:**

```txt theme={null}
log10(10) // 1
```

**Note:** It can also be written as a transform when the first value is the input: `value | log10(...)`.

### `log2`

Returns the base-2 logarithm of a number

**Signature:** `log2(x)`

**Example:**

```txt theme={null}
log2(2) // 1
```

**Note:** It can also be written as a transform when the first value is the input: `value | log2(...)`.

### `median`

Returns the median of all arguments

**Signature:** `median(...values)`

**Example:**

```txt theme={null}
median(1, 2, 3) // 2
```

**Note:** It can also be written as a transform when the first value is the input: `value | median(...)`.

### `mode`

Returns the mode (most frequent value) of all arguments

**Signature:** `mode(...values)`

**Example:**

```txt theme={null}
mode(1, 2, 2, 3) // 2
```

**Note:** It can also be written as a transform when the first value is the input: `value | mode(...)`.

### `pow`

Returns the base raised to the power of the exponent

**Signature:** `pow(base, exponent)`

**Example:**

```txt theme={null}
pow(2, 3) // 8
```

**Note:** It can also be written as a transform when the first value is the input: `value | pow(...)`.

### `random`

Returns a random number between 0 (inclusive) and 1 (exclusive)

**Signature:** `random()`

**Example:**

```txt theme={null}
random() // 0.123456789
```

**Note:** It can also be written as a transform when the first value is the input: `value | random(...)`.

### `round`

Returns the value of a number rounded to the nearest integer, with optional precision

**Signature:** `round(x, precision?)`

**Example:**

```txt theme={null}
round(4.74, 1) // 4.7
```

**Note:** It can also be written as a transform when the first value is the input: `value | round(...)`.

### `roundTo`

Rounds a number to a specified number of decimal places

**Signature:** `roundTo(value, decimals)`

**Example:**

```txt theme={null}
roundTo(3.14159, 2) // 3.14
```

**Note:** It can also be written as a transform when the first value is the input: `value | roundTo(...)`.

### `sign`

Returns the sign of a number

**Signature:** `sign(x)`

**Example:**

```txt theme={null}
sign(5) // 1
```

**Note:** It can also be written as a transform when the first value is the input: `value | sign(...)`.

### `sin`

Returns the sine of a number (in radians)

**Signature:** `sin(x)`

**Example:**

```txt theme={null}
sin(0) // 0
```

**Note:** It can also be written as a transform when the first value is the input: `value | sin(...)`.

### `sqrt`

Returns the square root of a number

**Signature:** `sqrt(x)`

**Example:**

```txt theme={null}
sqrt(9) // 3
```

**Note:** It can also be written as a transform when the first value is the input: `value | sqrt(...)`.

### `stddev`

Returns the standard deviation of all arguments

**Signature:** `stddev(...values)`

**Example:**

```txt theme={null}
stddev(1, 2, 3) // 0.816496580927726
```

**Note:** It can also be written as a transform when the first value is the input: `value | stddev(...)`.

### `tan`

Returns the tangent of a number (in radians)

**Signature:** `tan(x)`

**Example:**

```txt theme={null}
tan(0) // 0
```

**Note:** It can also be written as a transform when the first value is the input: `value | tan(...)`.

### `toDegrees`

Converts radians to degrees

**Signature:** `toDegrees(radians)`

**Example:**

```txt theme={null}
toDegrees(3.141592653589793) // 180
```

**Note:** It can also be written as a transform when the first value is the input: `value | toDegrees(...)`.

### `toRadians`

Converts degrees to radians

**Signature:** `toRadians(degrees)`

**Example:**

```txt theme={null}
toRadians(180) // 3.141592653589793
```

**Note:** It can also be written as a transform when the first value is the input: `value | toRadians(...)`.

### `trunc`

Returns the integer part of a number by removing fractional digits

**Signature:** `trunc(x)`

**Example:**

```txt theme={null}
trunc(4.9) // 4
```

**Note:** It can also be written as a transform when the first value is the input: `value | trunc(...)`.

### `variance`

Returns the variance of all arguments

**Signature:** `variance(...values)`

**Example:**

```txt theme={null}
variance(1, 2, 3) // 0.6666666666666666
```

**Note:** It can also be written as a transform when the first value is the input: `value | variance(...)`.

## Before you publish

* Start with a known value and confirm the expected result.
* Handle null, empty text, and empty lists deliberately.
* Do not place secrets, access tokens, or sensitive personal data in an expression.
* Read [expression contexts and availability](/reference/expressions/contexts) before copying an expression between features.

![Math helpers in KayanOS](https://kayanos.app/docs-images/en/reference/expressions-helpers-math.png)
