Kotlin 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 typeDoublefor 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)isNaNln(n)isNaNifn < 0.0ln(+Inf)is+Infln(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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours