-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add NaN and Inf support; allow result-as-operand #33
Conversation
I started reviewing today. No need to split, but yeah, this review will take a while. |
This PR is in good shape despite the many comments below. On subject of testing, I haven't looked at the IBM tests carefully (and the exclusions) because I know that they're pretty comprehensive, but do you know what kind of branch coverage they achieve on this code? Reviewed 8 of 8 files at r1, 2 of 2 files at r2, 1 of 1 files at r3, 1 of 1 files at r4. const.go, line 79 at r1 (raw file):
Could there be other places that need this fix? context.go, line 125 at r1 (raw file):
Maybe unify the branches below with
context.go, line 173 at r1 (raw file):
This would be subsumed by context.go, line 175 at r1 (raw file):
Since For this branch, atomically with the below suggestion, suggest
context.go, line 179 at r1 (raw file):
Atomically with the above suggestion, suggest context.go, line 189 at r1 (raw file):
context.go, line 232 at r1 (raw file):
This logic could be simplified to
Definitely at least suppress the special case for context.go, line 280 at r1 (raw file):
Don't we need to check whether context.go, line 283 at r1 (raw file):
Idle question: how does setting a very small exponent interact with context.go, line 410 at r1 (raw file):
Could the duplicate logic here be pulled out as (e.g.) context.go, line 441 at r1 (raw file):
Why NaN instead of rounding? The spec seems silent on this issue. context.go, line 462 at r1 (raw file):
Don't we need to invert the sign when y is negative? IIRC, floating point division should satisfy -x / y = x / -y = -(x / y). context.go, line 617 at r1 (raw file):
Does this context.go, line 891 at r1 (raw file):
context.go, line 934 at r1 (raw file):
How many of these functions need to set the Form field? I guess the transcendental functions don't because they're computed by iterative algorithms that use lower-level functions. context.go, line 1214 at r1 (raw file):
Could this check go in decimal.go, line 43 at r1 (raw file):
I had to read this comment a couple times to get it. Perhaps " decimal.go, line 114 at r1 (raw file):
Rather than count here, perhaps introduce a function like
and use throughout. decimal.go, line 132 at r1 (raw file):
Couldn't this be done earlier? decimal.go, line 136 at r1 (raw file):
We're only looking for lowercase e now, so we can use decimal.go, line 244 at r1 (raw file):
Is it worth pulling out the duplicate handling for specials and negative numbers between this function and the previous function? decimal.go, line 511 at r1 (raw file):
Unless I'm mistaken, decimal.go, line 536 at r1 (raw file):
Probably decimal.go, line 568 at r1 (raw file):
Wait to define these until after checking the signs and leave a comment explaining them. It looks strange at first that the sign tests use ±1 while the rest uses the "constants". decimal.go, line 620 at r1 (raw file):
I'm confused by the inner functions. We never seem to set decimal.go, line 666 at r1 (raw file):
I prefer
decimal.go, line 686 at r1 (raw file):
Is the Form check necessary? gda_test.go, line 449 at r1 (raw file):
Doesn't gda_test.go, line 627 at r1 (raw file):
Comments from Reviewable |
I ran Review status: 6 of 8 files reviewed at latest revision, 29 unresolved discussions. const.go, line 79 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
I can't think of any. context.go, line 125 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
I spent a few minutes trying to get this to work (that is, all of your comments about this function) but failed, as some small subset of tests always failed. I agree it seems like there's a simpler solution than what we have here but I currently think it should be done in another PR. I've created #37 to track this. context.go, line 175 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
I've made the context.go, line 189 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Yes, this branch is covered during testing. context.go, line 232 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
This change fails 18 test cases. context.go, line 280 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
I don't think we need a Line 597 in c7ade12
(This is The precision check was added by me to prevent footgun problems. I think that this block should stay above the precision check because in these cases we can produce correct, fast results. context.go, line 283 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
upscale returns an error if the differing exponents are too different: Line 350 in c7ade12
context.go, line 410 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. context.go, line 441 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
The spec says: "The exponent of the result must be 0. Hence, if the result cannot be expressed exactly within precision digits, the operation is in error and will fail – that is, the result cannot have more digits than the value of precision in effect for the operation, and will not be rounded." http://speleotrove.com/decimal/daops.html#refdivint context.go, line 462 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
The spec says: "The sign of the result, if non-zero, is the same as that of the original dividend." http://speleotrove.com/decimal/daops.html#refremain So I guess we don't satisfy that. context.go, line 617 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
It does (see the changes to cuberoot-apd.decTest), and it should do exactly the same thing Sqrt does for these inputs, I think. context.go, line 891 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. context.go, line 934 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
All functions must set the Form field. I added stuff to gda_test.go that fills in a bogus Form value to make sure it always gets set. And yes, the transcendental functions don't need to explicitly set it because of the simpler functions that do. But overall I'm convinced that all branches set Form because of the gda_test modification described. context.go, line 1214 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. decimal.go, line 43 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. But I'm not sure what further assumptions you are referring to. decimal.go, line 114 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. decimal.go, line 132 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. decimal.go, line 136 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. decimal.go, line 244 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. decimal.go, line 511 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Good catch. I didn't put together that decimal.go, line 536 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
This triggered a huge exploration that uncovered various bugs in decimal.go, line 568 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. decimal.go, line 620 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
I think I did this for a better reason that then got refactored away. Removed this functions. decimal.go, line 666 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. decimal.go, line 686 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
I thought it was, but since Sign() can only return 0 if d is Finite, I agree it isn't necessary. Removed. gda_test.go, line 449 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
This is checking the second operand. Quantize takes an int32 instead of a Decimal as the second operand, and so we skip all tests where the second operand isn't finite. gda_test.go, line 627 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. Comments from Reviewable |
Thanks for writing additional tests. Reviewed 1 of 8 files at r1, 1 of 1 files at r4, 7 of 7 files at r5. context.go, line 125 at r1 (raw file): Previously, mjibson (Matt Jibson) wrote…
OK, I'll try again out of band. context.go, line 280 at r1 (raw file): Previously, mjibson (Matt Jibson) wrote…
I guess this is a special case of positive decimal divided by zero. context.go, line 617 at r1 (raw file): Previously, mjibson (Matt Jibson) wrote…
Weird - - I would have expected it to copy the sign of its input, since x^3 - a has exactly one real root for all a. I don't remember if SQL has cbrt, but if it does, we should think about the alignment between this function and IEEE cbrt, which accepts negative numbers. context.go, line 1257 at r5 (raw file):
Do we mutate either v or neg above? Wondering why this isn't I guess I can answer my own question: because d and v may be aliased. decimal.go, line 43 at r1 (raw file): Previously, mjibson (Matt Jibson) wrote…
That for all constant values c1 and c2, -(c1 + 1) is less than c2 + 1. Maybe not comment-worthy since I don't expect this enumeration to change, but a little unusual. Comments from Reviewable |
CmpTotal wasn't tested before and had some bugs around Finite comparison. It now works correctly, and as a result fleshed out various other bugs where we expected -0 but were getting 0. The Rounding stuff was changed to a string because add has a special requirement during floor rounding, and there's not a good way to compare functions in Go. Using strings also allows users to inspect their context better, so it seems like a good change.
Review status: all files reviewed at latest revision, 11 unresolved discussions. context.go, line 617 at r1 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
You are correct. Cbrt should support negative numbers. I didn't think that through completely. I've opened #38 to track this. context.go, line 1257 at r5 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
I was able to remove this completely. The problem was the Comments from Reviewable |
This is a fairly big PR and incorporates two different features. I can break it up into 2 PRs if you prefer, but it's at least different commits. No rush on this since it's pretty big. Also I'm happy to find another reviewer if you'd prefer to not do it.
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)