Is there a reason that scala.math.signum is implemented in scala
def signum(x: Double): Double =
if (x == 0d) 0d
else if (x < 0) -1.0
else if (x > 0) 1.0
else x // NaN
and not delegated to the Java implementation
def signum(x: Double): Double = java.lang.Math.signum(x)
The behavior is different on negative zero (-0d). The above Scala implementation returns 0d whereas the Java implementation returns -0d (realized that when I looked at SI-5766).
The Scala code could easily be fixed by writing
def signum(x: Double): Double =
if (x == 0d) x
else if (x < 0) -1.0
else if (x > 0) 1.0
else x // NaN
Btw: ijuma wrote in https://github.com/scala/scala/commit/771f5ca5a11541866b57481ce0068fe8511c320d that
The Java implementation is faster as it doesn't have branches.
java.lang.Math includes implementations of signum for Double and Float,
but I didn't change the ones in scala.math because there is a difference
on how negative zero is handled.
This difference to the Java behavior should either be eliminated or documented.
Dominik