fn ln_near_one<T>(y: T) -> Twhere
T: FixedPointNumber + Copy + PartialOrd + FixedPointInfo,
T::Inner: From<u8> + Shr<u32, Output = T::Inner> + TryInto<i128> + Copy,Expand description
Computes ln(y) for a fixed-point value y near 1 using the
arctanh series identity:
ln(y) = 2 * sum_{k=0}^{inf} t^(2k+1) / (2k+1)
where t = (y - 1) / (y + 1)Converges for all y > 0, with convergence rate determined by |t|.
The closer y is to 1, the smaller |t| and the faster convergence.
range_reduce_sqrt ensures y is in [0.5, 1.5] before calling
this function, keeping |t| <= 1/3 for fast, reliable convergence.
§Arguments
y- A fixed-point value near1. Caller must ensurey > 0. Results are inaccurate foryfar from1.
§Returns
An approximation of ln(y), accurate to within the type’s ULP for
inputs in [0.5, 1.5].
§Note
On unsigned types, y < 1 produces t = 0 (since y - 1 saturates
to zero), returning ln(y) = 0. This is incorrect for y < 1, but
the unsigned type guard in fixed_ln ensures this branch is never
reached for unsigned types with y < 1.