sign

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

Returns the sign of the given value x:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special cases:

  • sign(NaN) is NaN

  • sign(-0.0) is -0.0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sign(3.14)) // 1.0
println(sign(-3.14)) // -1.0
println(sign(0.0)) // 0.0
println(sign(Double.POSITIVE_INFINITY)) // 1.0
println(sign(Double.NEGATIVE_INFINITY)) // -1.0

// Special cases
println(sign(Double.NaN)) // NaN
println(sign(-0.0)) // -0.0 
   //sampleEnd
}

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

Returns the sign of the given value x:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special cases:

  • sign(NaN) is NaN

  • sign(-0.0) is -0.0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sign(3.14f)) // 1.0
println(sign(-3.14f)) // -1.0
println(sign(0.0f)) // 0.0
println(sign(Float.POSITIVE_INFINITY)) // 1.0
println(sign(Float.NEGATIVE_INFINITY)) // -1.0

// Special cases
println(sign(Float.NaN)) // NaN
println(sign(-0.0f)) // -0.0 
   //sampleEnd
}

expect val Double.sign: Double(source)

Returns the sign of this value:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special cases:

  • NaN.sign is NaN

  • (-0.0).sign is -0.0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(3.14.sign) // 1.0
println((-3.14).sign) // -1.0
println(0.0.sign) // 0.0
println(Double.POSITIVE_INFINITY.sign) // 1.0
println(Double.NEGATIVE_INFINITY.sign) // -1.0

// Special cases
println(Double.NaN.sign) // NaN
println((-0.0).sign) // -0.0 
   //sampleEnd
}

expect val Float.sign: Float(source)

Returns the sign of this value:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special cases:

  • NaN.sign is NaN

  • (-0.0).sign is -0.0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(3.14f.sign) // 1.0
println((-3.14f).sign) // -1.0
println(0.0f.sign) // 0.0
println(Float.POSITIVE_INFINITY.sign) // 1.0
println(Float.NEGATIVE_INFINITY.sign) // -1.0

// Special cases
println(Float.NaN.sign) // NaN
println((-0.0f).sign) // -0.0 
   //sampleEnd
}

expect val Int.sign: Int(source)
expect val Long.sign: Int(source)

Returns the sign of this value:

  • -1 if the value is negative,

  • 0 if the value is zero,

  • 1 if the value is positive

Since Kotlin

1.2
actual inline fun sign(x: Double): Double(source)
actual inline fun sign(x: Float): Float(source)

Returns the sign of the given value x:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • sign(NaN) is NaN

Since Kotlin

1.2

actual val Double.sign: Double(source)
actual val Float.sign: Float(source)

Returns the sign of this value:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • NaN.sign is NaN

Since Kotlin

1.2

actual val Int.sign: Int(source)
actual val Long.sign: Int(source)

Returns the sign of this value:

  • -1 if the value is negative,

  • 0 if the value is zero,

  • 1 if the value is positive

Since Kotlin

1.2
actual inline fun sign(x: Double): Double(source)
actual inline fun sign(x: Float): Float(source)

Returns the sign of the given value x:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • sign(NaN) is NaN

Since Kotlin

1.2

actual val Double.sign: Double(source)
actual val Float.sign: Float(source)

Returns the sign of this value:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • NaN.sign is NaN

Since Kotlin

1.2

actual val Int.sign: Int(source)
actual val Long.sign: Int(source)

Returns the sign of this value:

  • -1 if the value is negative,

  • 0 if the value is zero,

  • 1 if the value is positive

Since Kotlin

1.2
actual fun sign(x: Double): Double(source)
actual fun sign(x: Float): Float(source)

Returns the sign of the given value x:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • sign(NaN) is NaN

Since Kotlin

1.3

actual val Double.sign: Double(source)
actual val Float.sign: Float(source)

Returns the sign of this value:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • NaN.sign is NaN

Since Kotlin

1.3

actual val Int.sign: Int(source)
actual val Long.sign: Int(source)

Returns the sign of this value:

  • -1 if the value is negative,

  • 0 if the value is zero,

  • 1 if the value is positive

Since Kotlin

1.3
actual fun sign(x: Double): Double(source)
actual fun sign(x: Float): Float(source)

Returns the sign of the given value x:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • sign(NaN) is NaN

Since Kotlin

1.8

actual val Double.sign: Double(source)
actual val Float.sign: Float(source)

Returns the sign of this value:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • NaN.sign is NaN

Since Kotlin

1.8

actual val Int.sign: Int(source)
actual val Long.sign: Int(source)

Returns the sign of this value:

  • -1 if the value is negative,

  • 0 if the value is zero,

  • 1 if the value is positive

Since Kotlin

1.8
actual fun sign(x: Double): Double(source)
actual fun sign(x: Float): Float(source)

Returns the sign of the given value x:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • sign(NaN) is NaN

Since Kotlin

1.8

actual val Double.sign: Double(source)
actual val Float.sign: Float(source)

Returns the sign of this value:

  • -1.0 if the value is negative,

  • zero if the value is zero,

  • 1.0 if the value is positive

Special case:

  • NaN.sign is NaN

Since Kotlin

1.8

actual val Int.sign: Int(source)
actual val Long.sign: Int(source)

Returns the sign of this value:

  • -1 if the value is negative,

  • 0 if the value is zero,

  • 1 if the value is positive

Since Kotlin

1.8