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

(-0.0).abs == -0.0 when should == 0.0 #8102

Closed
scabug opened this issue Dec 27, 2013 · 2 comments
Closed

(-0.0).abs == -0.0 when should == 0.0 #8102

scabug opened this issue Dec 27, 2013 · 2 comments
Milestone

Comments

@scabug
Copy link

scabug commented Dec 27, 2013

math.abs(-0.0) returns 0.0 as it should, but (-0.0).abs returns -0.0. The reason is that math.abs directly calls java.lang.Math.abs but (-0.0).abs is implemented in Numeric.scala by checking if the value is < 0, which fails for -0.0.

One way to fix this is to use compare instead of lt:

scala> -0.0 compare 0
res3: Int = -1

scala> 0.0 compare 0
res4: Int = 0

There may well be other bugs involving -0.0.

@scabug
Copy link
Author

scabug commented Dec 27, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8102?orig=1
Reporter: Ben Wing (benwing)
Assignee: @clhodapp
Affected Versions: 2.10.3, 2.11.0-M7

@scabug scabug closed this as completed Jan 8, 2014
@scabug
Copy link
Author

scabug commented Jan 8, 2014

@retronym said:
scala/scala#3325

@scabug scabug added this to the 2.11.0-M8 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

1 participant