Library reference

Base-ten logarithm

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

log10

Simple example

How many tenfold steps lead to one hundred?

Start100
Result2.0
lesson.mojo
from std.math import log10

def main() raises:
    print(log10(Float64(100.0)))
Output
2.0
Advertisements

Everyday examples

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

Start1000
Result3.0
lesson.mojo
from std.math import log10

def main() raises:
    print(log10(Float64(1000.0)))
Output
3.0

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

Start10
Result1.0
lesson.mojo
from std.math import log10

def main() raises:
    print(log10(Float64(10.0)))
Output
1.0

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

Start10000
Result4.0
lesson.mojo
from std.math import log10

def main() raises:
    print(log10(Float64(10000.0)))
Output
4.0
Run the example
Terminal
mojo lesson.mojo
Official documentation