log

expect fun log(x: Double, base: Double): Double(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(log(64.0, 4.0)) // 3.0
println(log(100.0, 10.0)) // 2.0
// √4 = 2 -> log₄2 = ½
println(log(2.0, 4.0)) // 0.5

// Special cases
println(log(Double.NaN, 2.0)) // NaN
println(log(-1.0, 2.0)) // NaN
println(log(1.0, 1.0)) // NaN
println(log(Double.POSITIVE_INFINITY, 0.5)) // -Infinity
println(log(0.0, 0.5)) // Infinity 
   //sampleEnd
}

expect fun log(x: Float, base: Float): Float(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(log(9.0f, 3.0f)) // 2.0
println(log(1000.0f, 10.0f)) // 3.0
// √4 = 2 -> log₄2 = ½
println(log(2.0f, 4.0f)) // 0.5

// Special cases
println(log(Float.NaN, 2.0f)) // NaN
println(log(-1.0f, 2.0f)) // NaN
println(log(1.0f, 1.0f)) // NaN
println(log(Float.POSITIVE_INFINITY, 0.5f)) // -Infinity
println(log(0.0f, 0.5f)) // Infinity 
   //sampleEnd
}
actual fun log(x: Double, base: Double): Double(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(log(64.0, 4.0)) // 3.0
println(log(100.0, 10.0)) // 2.0
// √4 = 2 -> log₄2 = ½
println(log(2.0, 4.0)) // 0.5

// Special cases
println(log(Double.NaN, 2.0)) // NaN
println(log(-1.0, 2.0)) // NaN
println(log(1.0, 1.0)) // NaN
println(log(Double.POSITIVE_INFINITY, 0.5)) // -Infinity
println(log(0.0, 0.5)) // Infinity 
   //sampleEnd
}

actual inline fun log(x: Float, base: Float): Float(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(log(9.0f, 3.0f)) // 2.0
println(log(1000.0f, 10.0f)) // 3.0
// √4 = 2 -> log₄2 = ½
println(log(2.0f, 4.0f)) // 0.5

// Special cases
println(log(Float.NaN, 2.0f)) // NaN
println(log(-1.0f, 2.0f)) // NaN
println(log(1.0f, 1.0f)) // NaN
println(log(Float.POSITIVE_INFINITY, 0.5f)) // -Infinity
println(log(0.0f, 0.5f)) // Infinity 
   //sampleEnd
}
actual fun log(x: Double, base: Double): Double(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(log(64.0, 4.0)) // 3.0
println(log(100.0, 10.0)) // 2.0
// √4 = 2 -> log₄2 = ½
println(log(2.0, 4.0)) // 0.5

// Special cases
println(log(Double.NaN, 2.0)) // NaN
println(log(-1.0, 2.0)) // NaN
println(log(1.0, 1.0)) // NaN
println(log(Double.POSITIVE_INFINITY, 0.5)) // -Infinity
println(log(0.0, 0.5)) // Infinity 
   //sampleEnd
}

actual fun log(x: Float, base: Float): Float(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(log(9.0f, 3.0f)) // 2.0
println(log(1000.0f, 10.0f)) // 3.0
// √4 = 2 -> log₄2 = ½
println(log(2.0f, 4.0f)) // 0.5

// Special cases
println(log(Float.NaN, 2.0f)) // NaN
println(log(-1.0f, 2.0f)) // NaN
println(log(1.0f, 1.0f)) // NaN
println(log(Float.POSITIVE_INFINITY, 0.5f)) // -Infinity
println(log(0.0f, 0.5f)) // Infinity 
   //sampleEnd
}
actual fun log(x: Double, base: Double): Double(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   println(log(64.0, 4.0)) // 3.0
println(log(100.0, 10.0)) // 2.0
// √4 = 2 -> log₄2 = ½
println(log(2.0, 4.0)) // 0.5

// Special cases
println(log(Double.NaN, 2.0)) // NaN
println(log(-1.0, 2.0)) // NaN
println(log(1.0, 1.0)) // NaN
println(log(Double.POSITIVE_INFINITY, 0.5)) // -Infinity
println(log(0.0, 0.5)) // Infinity 
   //sampleEnd
}

actual fun log(x: Float, base: Float): Float(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   println(log(9.0f, 3.0f)) // 2.0
println(log(1000.0f, 10.0f)) // 3.0
// √4 = 2 -> log₄2 = ½
println(log(2.0f, 4.0f)) // 0.5

// Special cases
println(log(Float.NaN, 2.0f)) // NaN
println(log(-1.0f, 2.0f)) // NaN
println(log(1.0f, 1.0f)) // NaN
println(log(Float.POSITIVE_INFINITY, 0.5f)) // -Infinity
println(log(0.0f, 0.5f)) // Infinity 
   //sampleEnd
}
actual fun log(x: Double, base: Double): Double(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(log(64.0, 4.0)) // 3.0
println(log(100.0, 10.0)) // 2.0
// √4 = 2 -> log₄2 = ½
println(log(2.0, 4.0)) // 0.5

// Special cases
println(log(Double.NaN, 2.0)) // NaN
println(log(-1.0, 2.0)) // NaN
println(log(1.0, 1.0)) // NaN
println(log(Double.POSITIVE_INFINITY, 0.5)) // -Infinity
println(log(0.0, 0.5)) // Infinity 
   //sampleEnd
}

actual fun log(x: Float, base: Float): Float(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(log(9.0f, 3.0f)) // 2.0
println(log(1000.0f, 10.0f)) // 3.0
// √4 = 2 -> log₄2 = ½
println(log(2.0f, 4.0f)) // 0.5

// Special cases
println(log(Float.NaN, 2.0f)) // NaN
println(log(-1.0f, 2.0f)) // NaN
println(log(1.0f, 1.0f)) // NaN
println(log(Float.POSITIVE_INFINITY, 0.5f)) // -Infinity
println(log(0.0f, 0.5f)) // Infinity 
   //sampleEnd
}
actual fun log(x: Double, base: Double): Double(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(log(64.0, 4.0)) // 3.0
println(log(100.0, 10.0)) // 2.0
// √4 = 2 -> log₄2 = ½
println(log(2.0, 4.0)) // 0.5

// Special cases
println(log(Double.NaN, 2.0)) // NaN
println(log(-1.0, 2.0)) // NaN
println(log(1.0, 1.0)) // NaN
println(log(Double.POSITIVE_INFINITY, 0.5)) // -Infinity
println(log(0.0, 0.5)) // Infinity 
   //sampleEnd
}

actual fun log(x: Float, base: Float): Float(source)

Computes the logarithm of the value x to the given base.

Special cases:

  • log(x, b) is NaN if either x or b are NaN

  • log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0

  • log(+Inf, +Inf) is NaN

  • log(+Inf, b) is +Inf for b > 1 and -Inf for b < 1

  • log(0.0, b) is -Inf for b > 1 and +Inf for b < 1

See also logarithm functions for common fixed bases: ln, log10 and log2.

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(log(9.0f, 3.0f)) // 2.0
println(log(1000.0f, 10.0f)) // 3.0
// √4 = 2 -> log₄2 = ½
println(log(2.0f, 4.0f)) // 0.5

// Special cases
println(log(Float.NaN, 2.0f)) // NaN
println(log(-1.0f, 2.0f)) // NaN
println(log(1.0f, 1.0f)) // NaN
println(log(Float.POSITIVE_INFINITY, 0.5f)) // -Infinity
println(log(0.0f, 0.5f)) // Infinity 
   //sampleEnd
}