Menu

#137 wrong value returned from a large numbers being modded

closed-invalid
Other (88)
5
2003-02-10
2003-02-09
Anonymous
No

A very large number (such as 5^23) modulus, say 7, returns the
wrong value of 2.0. The correct is 3.0 I'm using JRE 1.4.1.

Discussion

  • Charles Reis

    Charles Reis - 2003-02-10

    Logged In: YES
    user_id=429731

    This is a bug in Java, and not in DrJava. You can verify it
    by dropping your code into a class, compiling it from the
    command line, and running it-- you will get the same result.

    I'm looking for some references to this behavior on the web
    right now, but I'm not finding any. I also tested this with
    "Math.pow(5, 23) % 5", which should obviously return 0.0 but
    returns 4.0. Seems that's near the threshold, because
    Math.pow(5, 22) works fine, but any larger exponents start
    acting strange. (Even though Double.MAX_VALUE is 1.8E308.)

    I'll see if I can find any more information about it, or
    else perhaps a bug can be filed with Sun.

     
  • Charles Reis

    Charles Reis - 2003-02-10

    Logged In: YES
    user_id=429731

    Actually, this isn't even a bug in Java. Another developer
    pointed out that double-precision numbers (per the IEEE
    spec) have 53 significant bits of precision. 5^23 requires
    54 bits, so there isn't enough precision to determine a
    correct modulus.

     
  • Charles Reis

    Charles Reis - 2003-02-10
    • assigned_to: nobody --> csreis
    • status: open --> closed-invalid
     

Log in to post a comment.

MongoDB Logo MongoDB