max
Returns the greater of two values.
Since Kotlin
1.5Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0, 1.0)) // 1.0
println(max(1.0, -1.0)) // 1.0
println(max(-3.0, -1.0)) // -1.0
println(max(-0.0, 0.0)) // 0.0
// special cases
println(max(Double.NaN, 0.0)) // NaN
println(max(-9000.0, Double.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE is ${max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE}") // true
println(max(Double.POSITIVE_INFINITY, Double.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0f, 1.0f)) // 1.0
println(max(1.0f, -1.0f)) // 1.0
println(max(-3.0f, -1.0f)) // -1.0
println(max(-0.0f, 0.0f)) // 0.0
// special cases
println(max(Float.NaN, 0.0f)) // NaN
println(max(-9000.0f, Float.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE is ${max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE}") // true
println(max(Float.POSITIVE_INFINITY, Float.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1, 1)) // 1
println(max(1, -1)) // 1
println(max(-3, -1)) // -1
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1L, 1L)) // 1
println(max(1L, -1L)) // 1
println(max(-3L, -1L)) // -1
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0, 1.0)) // 1.0
println(max(1.0, -1.0)) // 1.0
println(max(-3.0, -1.0)) // -1.0
println(max(-0.0, 0.0)) // 0.0
// special cases
println(max(Double.NaN, 0.0)) // NaN
println(max(-9000.0, Double.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE is ${max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE}") // true
println(max(Double.POSITIVE_INFINITY, Double.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0f, 1.0f)) // 1.0
println(max(1.0f, -1.0f)) // 1.0
println(max(-3.0f, -1.0f)) // -1.0
println(max(-0.0f, 0.0f)) // 0.0
// special cases
println(max(Float.NaN, 0.0f)) // NaN
println(max(-9000.0f, Float.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE is ${max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE}") // true
println(max(Float.POSITIVE_INFINITY, Float.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1, 1)) // 1
println(max(1, -1)) // 1
println(max(-3, -1)) // -1
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1L, 1L)) // 1
println(max(1L, -1L)) // 1
println(max(-3L, -1L)) // -1
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0, 1.0)) // 1.0
println(max(1.0, -1.0)) // 1.0
println(max(-3.0, -1.0)) // -1.0
println(max(-0.0, 0.0)) // 0.0
// special cases
println(max(Double.NaN, 0.0)) // NaN
println(max(-9000.0, Double.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE is ${max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE}") // true
println(max(Double.POSITIVE_INFINITY, Double.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0f, 1.0f)) // 1.0
println(max(1.0f, -1.0f)) // 1.0
println(max(-3.0f, -1.0f)) // -1.0
println(max(-0.0f, 0.0f)) // 0.0
// special cases
println(max(Float.NaN, 0.0f)) // NaN
println(max(-9000.0f, Float.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE is ${max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE}") // true
println(max(Float.POSITIVE_INFINITY, Float.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1, 1)) // 1
println(max(1, -1)) // 1
println(max(-3, -1)) // -1
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1L, 1L)) // 1
println(max(1L, -1L)) // 1
println(max(-3L, -1L)) // -1
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0, 1.0)) // 1.0
println(max(1.0, -1.0)) // 1.0
println(max(-3.0, -1.0)) // -1.0
println(max(-0.0, 0.0)) // 0.0
// special cases
println(max(Double.NaN, 0.0)) // NaN
println(max(-9000.0, Double.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE is ${max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE}") // true
println(max(Double.POSITIVE_INFINITY, Double.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0f, 1.0f)) // 1.0
println(max(1.0f, -1.0f)) // 1.0
println(max(-3.0f, -1.0f)) // -1.0
println(max(-0.0f, 0.0f)) // 0.0
// special cases
println(max(Float.NaN, 0.0f)) // NaN
println(max(-9000.0f, Float.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE is ${max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE}") // true
println(max(Float.POSITIVE_INFINITY, Float.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1, 1)) // 1
println(max(1, -1)) // 1
println(max(-3, -1)) // -1
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1L, 1L)) // 1
println(max(1L, -1L)) // 1
println(max(-3L, -1L)) // -1
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0, 1.0)) // 1.0
println(max(1.0, -1.0)) // 1.0
println(max(-3.0, -1.0)) // -1.0
println(max(-0.0, 0.0)) // 0.0
// special cases
println(max(Double.NaN, 0.0)) // NaN
println(max(-9000.0, Double.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE is ${max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE}") // true
println(max(Double.POSITIVE_INFINITY, Double.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0f, 1.0f)) // 1.0
println(max(1.0f, -1.0f)) // 1.0
println(max(-3.0f, -1.0f)) // -1.0
println(max(-0.0f, 0.0f)) // 0.0
// special cases
println(max(Float.NaN, 0.0f)) // NaN
println(max(-9000.0f, Float.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE is ${max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE}") // true
println(max(Float.POSITIVE_INFINITY, Float.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1, 1)) // 1
println(max(1, -1)) // 1
println(max(-3, -1)) // -1
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1L, 1L)) // 1
println(max(1L, -1L)) // 1
println(max(-3L, -1L)) // -1
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0, 1.0)) // 1.0
println(max(1.0, -1.0)) // 1.0
println(max(-3.0, -1.0)) // -1.0
println(max(-0.0, 0.0)) // 0.0
// special cases
println(max(Double.NaN, 0.0)) // NaN
println(max(-9000.0, Double.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE is ${max(Double.MIN_VALUE, 0.0) == Double.MIN_VALUE}") // true
println(max(Double.POSITIVE_INFINITY, Double.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
If either value is NaN, then the result is NaN.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1.0f, 1.0f)) // 1.0
println(max(1.0f, -1.0f)) // 1.0
println(max(-3.0f, -1.0f)) // -1.0
println(max(-0.0f, 0.0f)) // 0.0
// special cases
println(max(Float.NaN, 0.0f)) // NaN
println(max(-9000.0f, Float.NaN)) // NaN
// Note that MIN_VALUE has a different meaning compared to Long.MIN_VALUE or Int.MIN_VALUE
println("max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE is ${max(Float.MIN_VALUE, 0.0f) == Float.MIN_VALUE}") // true
println(max(Float.POSITIVE_INFINITY, Float.MAX_VALUE)) // Infinity
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1, 1)) // 1
println(max(1, -1)) // 1
println(max(-3, -1)) // -1
//sampleEnd
}Returns the greater of two values.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(max(-1L, 1L)) // 1
println(max(1L, -1L)) // 1
println(max(-3L, -1L)) // -1
//sampleEnd
}