[][src]Function nikisas::log10

pub fn log10(x: f32) -> f32

Computes decimal logarithm of a number.

Notes

Theoretical input domain is (0, max(f32)] ≈ (0, 3.40282347e+38], but near zero the values get quite inaccurate.

Examples

use nikisas::log10;
assert_eq!(log10(100.0), 2.0);

Implementation details

The following identity is used for computation of log10(x):

  log10(x) = ln(x) / ln(10) = ln(x) * log10(e)

For computing ln(x) we use ln routine and log10(e) is precomputed constant.

We would like to get exact values when the input number is a power of ten. However, in this case it's not that straightforward as in pow2. We fallback to the following faithful determination: If the computed value of log10(x) is close to an integer, than we assume that the input was indeed a power of ten. Then we return the rounded value. This is not always true because the tolerance for "closeness" is a bit bigger than in other cases throughout this library.