fixed_exp

Computes e^(x / 1e18) * 1e18 for an 18-decimal fixed-point (WAD) exponent, with integer arithmetic only. NULL propagates; an exponent outside [-41e18, 130e18] errors. 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 1e-17 relative for results of 1e17 or more; a few wei near 1e18 (exp(1e18) is 2718281828459045235); a tiny result keeps few digits (exp(-41e18) is 1, true 1.56).

Example

Runs locally

SELECT fixed_exp((-1000000000000000000)::INT256)::VARCHAR AS inverse_e_wad;
-- => [{"inverse_e_wad":"367879441171442321"}]

API reference

fixed_exp(INT256) #

Computes e^(x / 1e18) * 1e18 for an 18-decimal fixed-point (WAD) exponent, with integer arithmetic only. NULL propagates; an exponent outside [-41e18, 130e18] errors.

Inputs

Name Type Use
x INT256

Exponent with 18 decimals, in [-41e18, 130e18]: INT256, or UINT256 from 0 (a rate times a time from muldiv).

required positional

Returns

Name Type
result UINT256

WAD e^x. UINT256 e^(x / 1e18) * 1e18; NULL for NULL input. An exponent out of range errors.

fixed_exp(UINT256) #

Computes e^(x / 1e18) * 1e18 for a non-negative UINT256 WAD exponent of at most 130e18, such as a rate times a time from muldiv.

Inputs

Name Type Use
x UINT256

Exponent with 18 decimals, in [-41e18, 130e18]: INT256, or UINT256 from 0 (a rate times a time from muldiv).

required positional

Returns

Name Type
result UINT256

WAD e^x. UINT256 e^(x / 1e18) * 1e18; NULL for NULL input. An exponent out of range errors.

Overload examples

Runs locally

-- A continuously compounded rate of ln(1.143) (WAD) over 50 days, as a growth factor
SELECT fixed_exp(muldiv(133670644092229524::UINT256, 4320001::UINT256, 31536000::UINT256))::VARCHAR AS growth_wad;
-- => [{"growth_wad":"1018479726643403642"}]