log2
Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.2See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.2See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.2See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.2See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.2See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.2See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.3See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.3See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.8See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.8See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.8See 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
}Computes the binary logarithm (base 2) of the value x.
Since Kotlin
1.8See 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
}