[][src]Function nikisas::pow10

pub fn pow10(p: f32) -> f32

Computes 10 raised to a power.

Notes

The input domain is limited to approximately [log10(min(positive f32)), log10(max(f32))] ≈ [-37.9, 38.5] due to limits of machine representation.

Examples

use nikisas::pow10;
assert_eq!(pow10(-1.0), 0.1);

Implementation details

First, the special case when x is near zero is handled such that the result is simply 1. Otherwise, the input x is reduced to an integer k and real y such that

  x = k + y and |y| ≤ 1/2

Let us denote z = |y|. Approximation of 10^z is done using polynomial in the form:

  10^z ≈ 1 + z * P(z)

The "prefix" corresponds to coefficients of low-degree Taylor polynomial of 10^z for z = 0 and P is found using special minimax algorithm in Sollya.

Now we have

  10^y = if y ≥ 0 then 10^z else 1 / 10^z

The reconstruction of original value is then

10^x = 10^(k + y) = 10^k * 10^y

Computation of 10^y is (transitively) done using aforementioned polynomial approximation and multiply-and-square loop algorithm is used for computation of 10^k. Note that in this case, the maximum number of iterations is limited by log2(max(|input range of x|)) < 6.