log2

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.2

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0)) // 1.0
println(log2(1.0)) // 0.0
println(log2(8.0)) // 3.0

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

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.2

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0f)) // 1.0
println(log2(1.0f)) // 0.0
println(log2(8.0f)) // 3.0

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.2

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0)) // 1.0
println(log2(1.0)) // 0.0
println(log2(8.0)) // 3.0

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

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.2

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0f)) // 1.0
println(log2(1.0f)) // 0.0
println(log2(8.0f)) // 3.0

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.2

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0)) // 1.0
println(log2(1.0)) // 0.0
println(log2(8.0)) // 3.0

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

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.2

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0f)) // 1.0
println(log2(1.0f)) // 0.0
println(log2(8.0f)) // 3.0

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.3

See also

actual function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0)) // 1.0
println(log2(1.0)) // 0.0
println(log2(8.0)) // 3.0

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

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.3

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0f)) // 1.0
println(log2(1.0f)) // 0.0
println(log2(8.0f)) // 3.0

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.8

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0)) // 1.0
println(log2(1.0)) // 0.0
println(log2(8.0)) // 3.0

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

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.8

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0f)) // 1.0
println(log2(1.0f)) // 0.0
println(log2(8.0f)) // 3.0

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.8

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0)) // 1.0
println(log2(1.0)) // 0.0
println(log2(8.0)) // 3.0

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

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

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.8

See also

function for special cases.

Samples

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

fun main() { 
   //sampleStart 
   println(log2(2.0f)) // 1.0
println(log2(1.0f)) // 0.0
println(log2(8.0f)) // 3.0

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