ln()
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 typeDouble
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)
isNaN
ln(n)
isNaN
ifn < 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
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours