ln

expect fun ln(x: Double): Double(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ln(E)) // 1.0
println(ln(1.0)) // 0.0
println(ln(E * E)) // 2.0

// Special cases
println(ln(Double.NaN)) // NaN
println(ln(-1.0)) // NaN
println(ln(0.0)) // -Infinity
println(ln(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

expect fun ln(x: Float): Float(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println("abs(ln(E.toFloat()) - 1.0f) < 1e7f is ${abs(ln(E.toFloat()) - 1.0f) < 1e7f}") // true
println(ln(1.0f)) // 0.0
println(ln(E.toFloat() * E.toFloat())) // 2.0

// Special cases
println(ln(Float.NaN)) // NaN
println(ln(-1.0f)) // NaN
println(ln(0.0f)) // -Infinity
println(ln(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual inline fun ln(x: Double): Double(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ln(E)) // 1.0
println(ln(1.0)) // 0.0
println(ln(E * E)) // 2.0

// Special cases
println(ln(Double.NaN)) // NaN
println(ln(-1.0)) // NaN
println(ln(0.0)) // -Infinity
println(ln(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual inline fun ln(x: Float): Float(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println("abs(ln(E.toFloat()) - 1.0f) < 1e7f is ${abs(ln(E.toFloat()) - 1.0f) < 1e7f}") // true
println(ln(1.0f)) // 0.0
println(ln(E.toFloat() * E.toFloat())) // 2.0

// Special cases
println(ln(Float.NaN)) // NaN
println(ln(-1.0f)) // NaN
println(ln(0.0f)) // -Infinity
println(ln(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual inline fun ln(x: Double): Double(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ln(E)) // 1.0
println(ln(1.0)) // 0.0
println(ln(E * E)) // 2.0

// Special cases
println(ln(Double.NaN)) // NaN
println(ln(-1.0)) // NaN
println(ln(0.0)) // -Infinity
println(ln(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual inline fun ln(x: Float): Float(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println("abs(ln(E.toFloat()) - 1.0f) < 1e7f is ${abs(ln(E.toFloat()) - 1.0f) < 1e7f}") // true
println(ln(1.0f)) // 0.0
println(ln(E.toFloat() * E.toFloat())) // 2.0

// Special cases
println(ln(Float.NaN)) // NaN
println(ln(-1.0f)) // NaN
println(ln(0.0f)) // -Infinity
println(ln(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual external fun ln(x: Double): Double(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ln(E)) // 1.0
println(ln(1.0)) // 0.0
println(ln(E * E)) // 2.0

// Special cases
println(ln(Double.NaN)) // NaN
println(ln(-1.0)) // NaN
println(ln(0.0)) // -Infinity
println(ln(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual external fun ln(x: Float): Float(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println("abs(ln(E.toFloat()) - 1.0f) < 1e7f is ${abs(ln(E.toFloat()) - 1.0f) < 1e7f}") // true
println(ln(1.0f)) // 0.0
println(ln(E.toFloat() * E.toFloat())) // 2.0

// Special cases
println(ln(Float.NaN)) // NaN
println(ln(-1.0f)) // NaN
println(ln(0.0f)) // -Infinity
println(ln(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual fun ln(x: Double): Double(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ln(E)) // 1.0
println(ln(1.0)) // 0.0
println(ln(E * E)) // 2.0

// Special cases
println(ln(Double.NaN)) // NaN
println(ln(-1.0)) // NaN
println(ln(0.0)) // -Infinity
println(ln(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual fun ln(x: Float): Float(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println("abs(ln(E.toFloat()) - 1.0f) < 1e7f is ${abs(ln(E.toFloat()) - 1.0f) < 1e7f}") // true
println(ln(1.0f)) // 0.0
println(ln(E.toFloat() * E.toFloat())) // 2.0

// Special cases
println(ln(Float.NaN)) // NaN
println(ln(-1.0f)) // NaN
println(ln(0.0f)) // -Infinity
println(ln(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual fun ln(x: Double): Double(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ln(E)) // 1.0
println(ln(1.0)) // 0.0
println(ln(E * E)) // 2.0

// Special cases
println(ln(Double.NaN)) // NaN
println(ln(-1.0)) // NaN
println(ln(0.0)) // -Infinity
println(ln(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual fun ln(x: Float): Float(source)

Computes the natural logarithm (base E) of the value x.

Special cases:

  • ln(NaN) is NaN

  • ln(x) is NaN when x < 0.0

  • ln(+Inf) is +Inf

  • ln(0.0) is -Inf

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println("abs(ln(E.toFloat()) - 1.0f) < 1e7f is ${abs(ln(E.toFloat()) - 1.0f) < 1e7f}") // true
println(ln(1.0f)) // 0.0
println(ln(E.toFloat() * E.toFloat())) // 2.0

// Special cases
println(ln(Float.NaN)) // NaN
println(ln(-1.0f)) // NaN
println(ln(0.0f)) // -Infinity
println(ln(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}