-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
JDK-8294539: Augment discussion of equivalence relations on floating-point values #10498
Conversation
👋 Welcome back darcy! A progress list of the required criteria for merging this PR into |
* <br>{@code Double.doubleToRawLongBits(a) == Double.doubleToRawLongBits(b)}<br> | ||
* Under this relation, {@code +0.0} and {@code -0.0} are distinguished | ||
* from each other and every bit pattern encoding a NaN is distinguished | ||
* form other bit patterns encoding a NaN. |
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.
s/form/from
* Note that representation equivalence is often an appropriate notion | ||
* of equivalence to test the behavior of {@linkplain StrictMath math | ||
* libraries}. | ||
* </dd> |
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.
This list deserves to include the not-quite-equivalence relation ==
. Suggest:
- numerical equivalence
- {@code +0.0} and {@code -0.0} are equivalent to each other.
- infinite numbers of the same sign are equivalent to each other
The two floating point numbers represent the same mathematical finite value or signed infinity.
Expressions implementing this ER include x == y
, x > y | x < y
, etc.
Numerical equivalence does not apply to NaN, as NaN violates the reflexive property required of all equivalences, but on the domain of all non-NaNs, numerical equivalence is in fact an equivalence relation.
Webrevs
|
* <dd>The bits of the two floating-point values are the same. This | ||
* equivalence relation for {@code double} values {@code a} and {@code b} is | ||
* implemented by the expression | ||
* <br>{@code Double.doubleTo}<code><b>Raw</b></code>{@code LongBits(a) == Double.doubleTo}<code><b>Raw</b></code>{@code LongBits(b)}<br> |
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.
Place in a code snippet since it's hard to read in source otherwise? Snippets allow for highlighting e.g.
/**
* {@snippet :
* Double.doubleToRawLongBits(a) == Double.doubleToRawLongBits(b) // @highlight substring="Raw"
* }
*/
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.
Before sending out the PR, I used a snippet, but it formatted the code using too much vertical space for the definition list. I didn't look to see if there was a "compact" styling option that could be used.
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.
Ok, i am not aware of a compact style.
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.
Filed JDK-8294814
@jddarcy This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 15 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
* <p>While {@code ==} is not an equivalence relation, several useful | ||
* equivalence relations can be defined over floating-point | ||
* values. Comparing numerical equality to various kinds of | ||
* equivalence: |
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 overall discussion is good, and the inclusion of numerical equality is good, but now this introductory paragraph is invalid. It starts off:
While
==
is not an equivalence relation,
OK, this continues the discussion, picking up from the assertion several paragraphs above that ==
is not an equivalence relation. Then,
several useful equivalence relations can be defined over floating-point values. Comparing numerical equality to various kinds of equivalence:
It sounds like what follows will be a list of equivalence relations that will be contrasted with numerical equality, yet the very first example is numerical equality and is not an equivalence relation.
I think this just needs to be reworded to be more inclusive. Maybe something like, "the following is a comparison of various relations among floating-point values."
* <ul> | ||
* <li> {@code +0.0} and {@code -0.0} are distinguished from each other. | ||
* <li> every bit pattern encoding a NaN is considered equivalent to each other | ||
* <li> an infinite value is equivalent to an infinite value of the same sign |
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.
Seems like this line on infinities could be reworded. I wouldn't quibble over this except that I had to read it several times to figure out what it meant. The statement on NaN is universally quantified, whereas the statement on infinite values starts off sounding like an existential quantifier. Possibly: "all infinite values of the same sign are considered equivalent to each other."
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.
Update as suggested and added some cross-links in from BigDecimal; thanks.
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.
PS To further spell things out, I added an additional trailing paragraph:
"For two binary floating-point values a and b, if neither of a and b is zero or NaN, then the three relations numerical equality, bit-wise equivalence, and representation equivalence of a and b have the same true/false value. In other words, for binary floating-point values, the three relations only differ if at least one argument is zero or NaN."
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 additional paragraph sounds fine.
/integrate |
Going to push as commit 1dafbe3.
Your commit was automatically rebased without conflicts. |
While the floating-point == operation is not an equivalence relation, there are useful equivalence relations that can be defined over floating-point values. Text is added to java.lang.Double to discuss and name those relations.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10498/head:pull/10498
$ git checkout pull/10498
Update a local copy of the PR:
$ git checkout pull/10498
$ git pull https://git.openjdk.org/jdk pull/10498/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 10498
View PR using the GUI difftool:
$ git pr show -t 10498
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10498.diff