Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double's signum should return 0 for -0d. #5766

Closed
scabug opened this issue May 7, 2012 · 3 comments
Closed

Double's signum should return 0 for -0d. #5766

scabug opened this issue May 7, 2012 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 7, 2012

Currently, (-0d).signum returns -1. I would expect this to return 0. For reference, the following works fine:

assert(scala.math.signum(-0d) == 0)
assert(java.lang.Math.signum(-0d) == 0)

But this blows up:

assert((-0d).signum == 0)

I am aware you want to follow Java's java.lang.Double.compare for Ordering (which strangely believes 0 * -1.0 < 0.0), but in this case I believe we should follow math/Math.signum's lead.

I think this would require overriding signum in DoubleIsConflicted from Numeric.scala.

@scabug
Copy link
Author

scabug commented May 7, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5766?orig=1
Reporter: Thomas Switzer (tixxit)
Affected Versions: 2.9.2
Other Milestones: 2.10.0-M3

@scabug
Copy link
Author

scabug commented May 7, 2012

@dgruntz said:
This is fixed in the 2.10.0 M3:

scala> scala.math.signum(-0d)
res0: Double = 0.0

scala> java.lang.Math.signum(-0d)
res1: Double = -0.0

scala> (-0d).signum
res2: Int = 0

@scabug scabug closed this as completed May 8, 2012
@scabug
Copy link
Author

scabug commented May 8, 2012

@dgruntz said:
Actually, in the current head release scala.math.signum(-0d) returns a negative zero (note, that a negative zero is equal to a positive zero if compared with ==).

scala> math.signum(-0d)
res0: Double = -0.0

scala> res0 == 0
res1: Boolean = true

@scabug scabug added this to the 2.10.0-M2 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants