double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)

Jeff Hain jeffhain at rocketmail.com
Mon Feb 11 13:53:19 PST 2013



Hello.



While testing some mathematical treatments,
I had "%" operator on doubles return NaN in
some cases where the divisor is subnormal
and the dividend either huge or tiny as well.



More precisely, with
D(x) = Double.longBitsToDouble(x),

I had a%b being NaN for:


- all (a,b) such as
  D(0x7FE0000000000000L) <= |a| <= D(0x7FEFFFFFFFFFFFFFL)
  and
  D(0x0000000000040000L) <= |b| <= D(0x000000000007FFFFL)


- plus for some values of |b| outside this range,
  when |a| is D(0x7FEFFFFFFFFFFFFFL), like
  b = D(0x000000007FFFFFFFL) (but not for b = D(0x000000007FFEFFFFL))
  b = 6.767486E-317
  b = 7.528725E-318




I can reproduce this on a Core i7 980X (64 bits),
with various versions of Java (64 bits), but not
on a Dual Core T2300 (32 bits), with various versions
of Java as well, so I wonder whether it's a JVM,
a CPU bug (by construction or if it broke) or else.


Is it a known issue, and if not can anyone
reproduce this weird behavior?



Thanks.

-Jeff


More information about the hotspot-dev mailing list