What is Math.log10() in Ruby?

The log10() function in Ruby returns the logarithm of a number using base 10.

Figure 1 shows the mathematical representation of the log10() function.

Figure 1: Mathematical representation of the log10() function

Syntax

log10(number)

Parameter

This function requires a number whose logarithm base 10 is to be calculated, and it must be greater than zero.

Return value

log10() uses base 10 to return the logarithm of a number.

Example

#example
print "log10(10) : ", Math.log10(10), "\n"
print "log10(2) : ", Math.log10(2), "\n"
#error
print "log10(0) : ", Math.log10(0), "\n"

Free Resources