ln()

manviii_27's avatar
Published Oct 18, 2023
Contribute to Docs

The ln() method in Kotlin’s math class is used to calculate the natural logarithm of a number.

Syntax

ln(n)
  • n: The number of type Double for which the logarithm is to be calculated.

The ln() method returns a value of type Double, the logarithm of n to e. The following values represent special cases:

  • ln(NaN) is NaN
  • ln(n) is NaN if n < 0.0
  • ln(+Inf) is +Inf
  • ln(0.0) is -Inf

Example

This example shows how to use the ln() method to calculate the natural logarithm of 6:

import kotlin.math.*
fun main(){
println(ln(6.0))
}

The output of this code will be:

1.791759469228055

All contributors

Contribute to Docs

Learn Kotlin on Codecademy