sign

Common
JVM
JS
Native
1.2
fun sign(x: Double): Double
fun sign(x: Float): Float

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
Common
Native
1.2
val Double.sign: Double
JVM
JS
1.2
inline val Double.sign: Double
Common
Native
1.2
val Float.sign: Float
JVM
JS
1.2
inline val Float.sign: Float

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
Common
JVM
JS
Native
1.2
val Int.sign: Int
val Long.sign: Int

Returns the sign of this value:

  • -1 if the value is negative,
  • 0 if the value is zero,
  • 1 if the value is positive