Permalink
Browse files

Changes scala.math.signum to return negative zeros.

  • Loading branch information...
dgruntz committed May 8, 2012
1 parent 8e88e5b commit c5d9e88b898dd73e8d60cfda89c6b9071657e2f3
Showing with 9 additions and 14 deletions.
  1. +3 −14 src/library/scala/math/package.scala
  2. +6 −0 test/files/jvm/signum.scala
@@ -115,21 +115,10 @@ package object math {
def min(x: Float, y: Float): Float = java.lang.Math.min(x, y)
def min(x: Double, y: Double): Double = java.lang.Math.min(x, y)
def signum(x: Double): Double =
if (x == 0d) 0d
else if (x < 0) -1.0
else if (x > 0) 1.0
else x // NaN
def signum(x: Float): Float =
if (x == 0f) 0f
else if (x < 0) -1.0f
else if (x > 0) 1.0f
else x // NaN
def signum(x: Long): Long = java.lang.Long.signum(x)
def signum(x: Int): Int = java.lang.Integer.signum(x)
def signum(x: Long): Long = java.lang.Long.signum(x)
def signum(x: Float): Float = java.lang.Math.signum(x)
def signum(x: Double): Double = java.lang.Math.signum(x)
// -----------------------------------------------------------------------
// root functions
@@ -11,5 +11,11 @@ object Test {
assert(math.signum(0) == 0)
assert(math.signum(-1) == -1)
assert(math.signum(Int.MinValue) == -1)
assert(java.lang.Float.floatToIntBits(math.signum(0f)) == 0x0)
assert(java.lang.Float.floatToIntBits(math.signum(-0f)) == 0x80000000)
assert(java.lang.Double.doubleToLongBits(math.signum(0d)) == 0x0L)
assert(java.lang.Double.doubleToLongBits(math.signum(-0d)) == 0x8000000000000000L)
}
}

0 comments on commit c5d9e88

Please sign in to comment.