fn fixed_exp<T>(x: &T) -> Option<T>where
T: FixedPointNumber + Copy + PartialOrd + FixedPointInfo,
T::Inner: From<u8> + Shr<u32, Output = T::Inner> + TryInto<i128> + Copy,Expand description
Computes e^x for a fixed-point number using argument reduction and
a Taylor series expansion.
§Algorithm
Splits x = n + r where n is the integer part and |r| <= 0.5:
exp(x) = exp(n) * exp(r)exp(r) is computed via Taylor series (fast for small |r|).
exp(n) is computed by raising e ~= 2.718281828459045235 to integer
power n via binary exponentiation (fixed_powi).
e is approximated as 2_718_281_828_459_045_235 / 10^18, giving
18 significant figures - matching the full precision of FixedU128
and over-specified but harmless for the other three types.
§Domain
Defined for all fixed-point values, but:
- Large positive
xoverflows the fixed-point range - returnsNone. - Large negative
xunderflows to zero - returnsSome(0). Threshold:x < -(DECIMAL_PLACES * 10).
§Arguments
x- The fixed-point exponent value.
§Returns
Some(exp(x))on successSome(0)whenxis below the underflow thresholdNoneon overflow, or if internal arithmetic fails
§Examples
ⓘ
let x = FixedU64::saturating_from_integer(1);
let result = fixed_exp(&x).unwrap();
// result ~= 2.718281828