Function dynamic_max_iterations

Source
fn dynamic_max_iterations<T>(x: &T) -> u32
where T: FixedPointNumber + Copy + FixedPointInfo, T::Inner: Shr<u32, Output = T::Inner> + TryInto<i128> + Copy,
Expand description

Computes an adaptive iteration count for series expansions based on the magnitude of x and the precision of the fixed-point type.

Larger inputs converge more slowly in series expansions, and higher precision types require more terms to reach their representable accuracy. This function combines both factors into a single iteration budget:

iterations = floor(|x|) * DECIMAL_PLACES + 1

The + 1 guarantees at least one iteration for any input, including x = 0.

§Arguments

  • x - The fixed-point value whose magnitude drives the iteration count.

§Returns

A u32 iteration count, always >= 1. Uses saturating arithmetic throughout so overflow on very large inputs produces u32::MAX rather than wrapping.