# fixed_ln

Computes ln(x / 1e18) * 1e18 for a positive 18-decimal fixed-point (WAD) value, with integer arithmetic only; arguments in (0.9e18, 1.1e18) use a 36-decimal series. NULL propagates. Results equal, digit for digit, those of the LogExpMath library that Balancer V2 and Pendle V2 contracts use, so a query recomputes an on-chain rate exactly. Accuracy: within 2 wei of the true value, on either side.

Canonical HTML: <https://determica.com/docs/functions/fixed_ln>

- Kind: scalar function
- Category: [Fixed-point and AMM math](/docs/category/fixed-point-and-amm-math.md)
- Tags: Fixed Point Math, Deterministic, Offline, Types

Computes ln(x / 1e18) * 1e18 for a positive 18-decimal fixed-point (WAD) value, with integer arithmetic only; arguments in (0.9e18, 1.1e18) use a 36-decimal series. NULL propagates. Results equal, digit for digit, those of the LogExpMath library that Balancer V2 and Pendle V2 contracts use, so a query recomputes an on-chain rate exactly. Accuracy: within 2 wei of the true value, on either side.

## Overload 1: fixed_ln(UINT256)

```sql
fixed_ln(UINT256)
```

Computes ln(x / 1e18) * 1e18 for a positive 18-decimal fixed-point (WAD) value, with integer arithmetic only; arguments in (0.9e18, 1.1e18) use a 36-decimal series. NULL propagates.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `x` (UINT256; required; positional) — UINT256 value with 18 decimals, in [1, 2^255 - 1].

### Returns

Signed WAD ln(x)

INT256 ln(x / 1e18) * 1e18, negative below 1e18. NULL for NULL input; zero or a value of 2^255 or more errors.

- `result` (INT256)

Signed WAD ln(x). INT256 ln(x / 1e18) * 1e18, negative below 1e18. NULL for NULL input; zero or a value of 2^255 or more errors.

### Examples

_Local SQL · Local_

```sql
SELECT fixed_ln(1427501850256585166::UINT256)::VARCHAR AS ln_rate_wad, fixed_ln(500000000000000000::UINT256)::VARCHAR AS ln_half_wad;
-- => [{"ln_rate_wad":"355925958698911634","ln_half_wad":"-693147180559945309"}]
```

## Related functions

- [fixed_exp](/docs/functions/fixed_exp.md) — Alternative
- [fixed_pow](/docs/functions/fixed_pow.md) — See Also
- [fixed_div](/docs/functions/fixed_div.md) — Usually Before
