The log10()
function uses the base 10 to calculate the logarithm of a number.
Figure 1 shows the mathematical representation of the log10()
function and the corresponding representation in Scala.
The following module is required for this function:
import scala.math._
Double log(Double number)
This function requires a number whose logarithm base 10 is to be calculated, and it must be greater than zero.
log10()
uses the base 10 to return the logarithm of a number.
- If the parameter value is positive infinity, then it returns positive infinity.
- If the parameter value is NaN, less than zero, or negative infinity, then it returns NaN.
- If the parameter value is zero, then it returns negative infinity.
The following example shows how we can use the log10()
function in Scala.
import scala.math._object Main extends App {//positive numberprintln(s"The value of log10(10) = ${log10(10)}");println(s"The value of log10(2) = ${log10(2)}");//error outputsprintln(s"The value of log10(Double.PositiveInfinity) = ${log10(Double.PositiveInfinity)}");println(s"The value of log10(Double.NegativeInfinity) = ${log10(Double.NegativeInfinity)}");println(s"The value of log10(Double.NaN) = ${log10(Double.NaN)}");println(s"The value of log10(-1) = ${log10(-1)}");println(s"The value of log10(0) = ${log10(0)}");}