Library reference

Base-ten logarithm

Count the number of tenfold steps between one and a positive value.

f64::log10

Simple example

How many tenfold steps lead to one hundred?

Start100
Result2
main.rs
fn main() {
    println!("{}", (100.0_f64).log10());
}
Output
2
Advertisements

Everyday examples

A map display offers zoom factors of 1, 10 and 1000. Which power of ten is the last setting?

Start1000
Result3
main.rs
fn main() {
    println!("{}", (1000.0_f64).log10());
}
Output
3

A light meter reads ten times its reference. How many tenfold steps is that?

Start10
Result1
main.rs
fn main() {
    println!("{}", (10.0_f64).log10());
}
Output
1

A graph marks a value of 10000 on a base-ten scale. Which exponent belongs on the axis?

Start10000
Result4
main.rs
fn main() {
    println!("{}", (10000.0_f64).log10());
}
Output
4
Run the example
Terminal
rustc main.rs
./main
Official documentation