abs
Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.2See also
extension property for Double
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14)) // 3.14
println(abs(-3.14)) // 3.14
println(abs(-0.0)) // 0.0
println(abs(Double.NEGATIVE_INFINITY)) // Infinity
println(abs(Double.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.2See also
extension property for Float
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(3.14f.absoluteValue) // 3.14
println((-3.14f).absoluteValue) // 3.14
println((-0.0f).absoluteValue) // 0.0
println(Float.NEGATIVE_INFINITY.absoluteValue) // Infinity
println(Float.NaN.absoluteValue) // NaN
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Int.MIN_VALUE)isInt.MIN_VALUEdue to an overflow
Since Kotlin
1.2See also
extension property for Int
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42)) // 42
println(abs(-42)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Int.MIN_VALUE) == Int.MIN_VALUE is ${abs(Int.MIN_VALUE) == Int.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Long.MIN_VALUE)isLong.MIN_VALUEdue to an overflow
Since Kotlin
1.2See also
extension property for Long
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42L)) // 42
println(abs(-42L)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Long.MIN_VALUE) == Long.MIN_VALUE is ${abs(Long.MIN_VALUE) == Long.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.2See also
extension property for Double
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14)) // 3.14
println(abs(-3.14)) // 3.14
println(abs(-0.0)) // 0.0
println(abs(Double.NEGATIVE_INFINITY)) // Infinity
println(abs(Double.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.2See also
extension property for Float
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14f)) // 3.14
println(abs(-3.14f)) // 3.14
println(abs(-0.0f)) // 0.0
println(abs(Float.NEGATIVE_INFINITY)) // Infinity
println(abs(Float.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Int.MIN_VALUE)isInt.MIN_VALUEdue to an overflow
Since Kotlin
1.2See also
extension property for Int
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42)) // 42
println(abs(-42)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Int.MIN_VALUE) == Int.MIN_VALUE is ${abs(Int.MIN_VALUE) == Int.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Long.MIN_VALUE)isLong.MIN_VALUEdue to an overflow
Since Kotlin
1.2See also
extension property for Long
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42L)) // 42
println(abs(-42L)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Long.MIN_VALUE) == Long.MIN_VALUE is ${abs(Long.MIN_VALUE) == Long.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.2See also
extension property for Double
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14)) // 3.14
println(abs(-3.14)) // 3.14
println(abs(-0.0)) // 0.0
println(abs(Double.NEGATIVE_INFINITY)) // Infinity
println(abs(Double.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.2See also
extension property for Float
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14f)) // 3.14
println(abs(-3.14f)) // 3.14
println(abs(-0.0f)) // 0.0
println(abs(Float.NEGATIVE_INFINITY)) // Infinity
println(abs(Float.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Int.MIN_VALUE)isInt.MIN_VALUEdue to an overflow
Since Kotlin
1.2See also
extension property for Int
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42)) // 42
println(abs(-42)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Int.MIN_VALUE) == Int.MIN_VALUE is ${abs(Int.MIN_VALUE) == Int.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Long.MIN_VALUE)isLong.MIN_VALUEdue to an overflow
Since Kotlin
1.2See also
extension property for Long
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42L)) // 42
println(abs(-42L)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Long.MIN_VALUE) == Long.MIN_VALUE is ${abs(Long.MIN_VALUE) == Long.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.3See also
extension property for Double
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14)) // 3.14
println(abs(-3.14)) // 3.14
println(abs(-0.0)) // 0.0
println(abs(Double.NEGATIVE_INFINITY)) // Infinity
println(abs(Double.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.3See also
extension property for Float
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14f)) // 3.14
println(abs(-3.14f)) // 3.14
println(abs(-0.0f)) // 0.0
println(abs(Float.NEGATIVE_INFINITY)) // Infinity
println(abs(Float.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Int.MIN_VALUE)isInt.MIN_VALUEdue to an overflow
Since Kotlin
1.3See also
extension property for Int
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42)) // 42
println(abs(-42)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Int.MIN_VALUE) == Int.MIN_VALUE is ${abs(Int.MIN_VALUE) == Int.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Long.MIN_VALUE)isLong.MIN_VALUEdue to an overflow
Since Kotlin
1.3See also
extension property for Long
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42L)) // 42
println(abs(-42L)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Long.MIN_VALUE) == Long.MIN_VALUE is ${abs(Long.MIN_VALUE) == Long.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.8See also
extension property for Double
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14)) // 3.14
println(abs(-3.14)) // 3.14
println(abs(-0.0)) // 0.0
println(abs(Double.NEGATIVE_INFINITY)) // Infinity
println(abs(Double.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.8See also
extension property for Float
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14f)) // 3.14
println(abs(-3.14f)) // 3.14
println(abs(-0.0f)) // 0.0
println(abs(Float.NEGATIVE_INFINITY)) // Infinity
println(abs(Float.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Int.MIN_VALUE)isInt.MIN_VALUEdue to an overflow
Since Kotlin
1.8See also
extension property for Int
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42)) // 42
println(abs(-42)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Int.MIN_VALUE) == Int.MIN_VALUE is ${abs(Int.MIN_VALUE) == Int.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Long.MIN_VALUE)isLong.MIN_VALUEdue to an overflow
Since Kotlin
1.8See also
extension property for Long
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42L)) // 42
println(abs(-42L)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Long.MIN_VALUE) == Long.MIN_VALUE is ${abs(Long.MIN_VALUE) == Long.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.8See also
extension property for Double
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14)) // 3.14
println(abs(-3.14)) // 3.14
println(abs(-0.0)) // 0.0
println(abs(Double.NEGATIVE_INFINITY)) // Infinity
println(abs(Double.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value x.
Special cases:
abs(NaN)isNaN
Since Kotlin
1.8See also
extension property for Float
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(3.14f)) // 3.14
println(abs(-3.14f)) // 3.14
println(abs(-0.0f)) // 0.0
println(abs(Float.NEGATIVE_INFINITY)) // Infinity
println(abs(Float.NaN)) // NaN
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Int.MIN_VALUE)isInt.MIN_VALUEdue to an overflow
Since Kotlin
1.8See also
extension property for Int
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42)) // 42
println(abs(-42)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Int.MIN_VALUE) == Int.MIN_VALUE is ${abs(Int.MIN_VALUE) == Int.MIN_VALUE}") // true
//sampleEnd
}Returns the absolute value of the given value n.
Special cases:
abs(Long.MIN_VALUE)isLong.MIN_VALUEdue to an overflow
Since Kotlin
1.8See also
extension property for Long
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
println(abs(42L)) // 42
println(abs(-42L)) // 42
// Special case: can't get the absolute value due to an overflow
println("abs(Long.MIN_VALUE) == Long.MIN_VALUE is ${abs(Long.MIN_VALUE) == Long.MIN_VALUE}") // true
//sampleEnd
}