W3cubDocs

/Kotlin

sign

Platform and version requirements: JVM (1.2), JS (1.2), 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
Platform and version requirements: Native (1.2)
val Double.sign: Double
Platform and version requirements: JVM (1.2), JS (1.2)
inline val Double.sign: Double
Platform and version requirements: Native (1.2)
val Float.sign: Float
Platform and version requirements: JVM (1.2), 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
Platform and version requirements: JVM (1.2), JS (1.2), 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

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.math/sign.html