-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(kernel): treat +0.0 and -0.0 as equal in Double/Float Order #4893
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,31 @@ class OrderSuite extends CatsSuite { | |
| assert(OrderOfCmpSub.gt(OrderSuite.CmpSub(2, "ignored"), OrderSuite.CmpSub(1, "ignored"))) | ||
| assert(OrderOfCmpSub.eqv(OrderSuite.CmpSub(1, "a"), OrderSuite.CmpSub(1, "b"))) | ||
| } | ||
|
|
||
| // #4807: +0.0 and -0.0 must agree across eqv, compare, and derived Option eqv | ||
| test("#4807 Double signed zeros are equal under Order and Option") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests are pretty comprehensive, thank you!
That suggests that the checks could probably be extracted into a generic function and then run for
Also, it probably makes sense to split the tests according the type classes being tested:
I realize that this specific PR is focused on the specific issue, but long-term it may be confusing to see tests for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I’m not sure it’s generally a good idea to include the issue number in the test name. Test names should clearly describe what is being tested, rather than the issue that prompted the PR. If cross-referencing is useful (which it probably is) – adding the issue number to a code comment should be sufficient. |
||
| val pos = 0.0 | ||
| val neg = -0.0 | ||
| assert(Order[Double].eqv(pos, neg)) | ||
| assertEquals(Order[Double].compare(pos, neg), 0) | ||
| assert(cats.kernel.Hash[Double].hash(pos) === cats.kernel.Hash[Double].hash(neg)) | ||
| assert(Order[Option[Double]].eqv(Some(pos), Some(neg))) | ||
| assertEquals(Order[Option[Double]].compare(Some(pos), Some(neg)), 0) | ||
| assert((Some(pos): Option[Double]) === (Some(neg): Option[Double])) | ||
| assert(pos === neg) | ||
| } | ||
|
|
||
| test("#4807 Float signed zeros are equal under Order and Option") { | ||
| val pos = 0.0f | ||
| val neg = -0.0f | ||
| assert(Order[Float].eqv(pos, neg)) | ||
| assertEquals(Order[Float].compare(pos, neg), 0) | ||
| assert(cats.kernel.Hash[Float].hash(pos) === cats.kernel.Hash[Float].hash(neg)) | ||
| assert(Order[Option[Float]].eqv(Some(pos), Some(neg))) | ||
| assertEquals(Order[Option[Float]].compare(Some(pos), Some(neg)), 0) | ||
| assert((Some(pos): Option[Float]) === (Some(neg): Option[Float])) | ||
| assert(pos === neg) | ||
| } | ||
| } | ||
|
|
||
| object OrderSuite { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first thing that
Double.comparedoes is this:Is there a reason for repeating those
<and>comparisons in our code?How about this: