Math.nextAfter and .nextUp confused me at first because I'm still on
Java 1.5 and they're part of 1.6, but they'd be useful in implementing
a java.text.ChoiceFormat work-alike.
I don't have a need for the others.
Ian
--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com
BTW, since the code doesn't document exactly why it is supposed to work, here's my 'theory' on how this algorithm works to help review. To tell the truth, I'm not sure how correct it is around the margins, since I coded it according to the theory, and then 'fixed' it when some tests didn't work as expected.
(Patched in at r2201, if it matters for line numberings...)
Style question, I at least prefer capital "L" to indicate long constants, as lowercase 'l' looks like 1... does GWT code insist one way or the other?
doubleToLongBits,
- l.56, the "special cases" tests should be together... in particular, the test for Infinity should be near the test for NaN, and before the (irrelevant to that case) call to Math.abs().
- l.82, what's the "&& guess > 1024" clause for? I get that we're checking whether our putative mantissa is too small (fractional) and we should ramp down the exponent to raise it to at least one, but where does the 1024 come from? If the double is (fraction x 2^512), why wouldn't we want to adjust to (2*fraction x 2^256)?
- generally, we probably want symbolics for most of the constants. I know why most are there, but balked at 1024 and at 10231... oh, duh, that last is 1023L, and that's also where 1024 comes from. But I shouldn't have had to figure that out. ;-)
longBitsToDouble,
- name the input something other than 'l', for the same looks-like-a-1 reason I prefer constants ending in L,
- l.134 typo "out" -> "our" ?
damn it, I always forget to attach, here it is.On Wed, Mar 26, 2008 at 12:12 PM, Ray Cromwell <cromw...@gmail.com> wrote:
Ok, I made it explicit so that the code is easier to understand. Here's an updated patch, major changes since last time you looked:
1) explicit assignment of absV = 0 in Infinite case
2) All magic numbers/constants changed to static final fields
3) static final fields are package protected so upcoming java.lang.Math patch can access them
4) added "Theory" comments everywhere
5) recognized special cases according to your comments
6) literal longs l -> L
This code works in the JDK, but I never tested it in GWT web-mode, because I haven't used a build with Long Emulation yet. However, if Scott's Long Emulation is broken, this
is the patch that will exercise it. :)
-RayOn Wed, Mar 26, 2008 at 12:00 PM, Freeland Abbott <fab...@google.com> wrote:
This is a corner of a corner case; I'm not sure that I care. That said, if I'm forced to pick one, I think the explicit assignment seems cleaner; I don't think the performance cost is significant, and it makes the code much more "as expected" rather than "read the fine print."
On Wed, Mar 26, 2008 at 2:49 PM, Ray Cromwell <cromw...@gmail.com> wrote:
I just looked at my working previous patch and it has the same "bug". On testing, it's not a bug because of implicit conversions of NaN/INF.
That is, if x = Infinity
mantissa = (x % 1) * Math.pow(2,52)
(x % 1) = NaN
NaN * Math.pow(2,52) = NaN
But NaN & 0xANYBITS = 0, that is, Infinity and NaN get coerced to zero, so although I could add an explicit "x = 0" in that case, it would be a no-op.
Should I force the variable to be 0, or just comment on the implicit nature of it working.
I did rename NUMBER_BITSIZE back to SIZE, I'll attach a new patch based on your response.
-Ray
On Wed, Mar 26, 2008 at 7:52 AM, Freeland Abbott <gwt.team...@gmail.com> wrote:Glad I hadn't gotten to it, then!On Wed, Mar 26, 2008 at 2:54 AM, Ray Cromwell <cromw...@gmail.com> wrote:
Freeland,
I just reviewed my code again, I really fubared that patch. The case where d == Infinity fails, because of a missing line assigning absV = 0 (so that the mantissa becomes 0 , which is how Infinity is represented) Also, NUMBER_SIZE should be just SIZE which is the official JDK variable, I refactored this by accident. I'll send you a fixed version tommorow, hopefully the last one unless you find some issues. :)
-RayOn Tue, Mar 25, 2008 at 8:33 AM, Ray Cromwell <cromw...@gmail.com> wrote:
Yeah, but I made the mistake of changing the subject line, here it is: http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/419e9675df541dfd
On Tue, Mar 25, 2008 at 8:12 AM, Freeland Abbott <gwt.team...@gmail.com> wrote:Did you attach the patch?
-Ray
On Wed, Apr 9, 2008 at 11:37 AM, Freeland Abbott