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.

Example

Runs locally

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"}]

API reference

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.

Inputs

Name Type Use
x UINT256

UINT256 value with 18 decimals, in [1, 2^255 - 1].

required positional

Returns

Name Type
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.