Ruby Tutorial Ruby References

Ruby - Math.log10() Method



The Ruby Math.log10() method returns the base-10 logarithm of a given number.

Syntax

Math.log10(x)

Parameters

x Specify the number.

Return Value

Returns the base-10 logarithm of a given number.
If the x is negative, DomainError is thrown.
If the x is 0, it returns -Infinity.

Example:

In the example below, Math.log10() method is used to calculate the base-10 logarithm of a given number.

puts "Math.log10(1) = #{Math.log10(1)}"
puts "Math.log10(10) = #{Math.log10(10)}"
puts "Math.log10(50) = #{Math.log10(50)}"
puts "Math.log10(0) = #{Math.log10(0)}"

The output of the above code will be:

Math.log10(1) = 0.0
Math.log10(10) = 1.0
Math.log10(50) = 1.6989700043360187
Math.log10(0) = -Infinity

❮ Ruby Math Module