Menu

#4973 mod of a large float returns 0.0 regardless of the true residue

None
open
nobody
5
13 hours ago
13 hours ago
No

mod(1.0e17, 3.0) returns 0.0 where the residue is 1

Maxima 5.49post, SBCL 2.6.7.

1.0e17 is exactly 100000000000000000 as a double, and both that value and the residue are exactly representable, so nothing here is ill-conditioned.

(%i1) display2d:false$
(%i2) ratprint:false$
(%i3) for t in [[1.0e15,3.0],[1.0e16,3.0],[1.0e17,3.0],[1.0e20,7.0],
                [-1.0e17,3.0],[1.0e17,-3.0]] do
        printf(true, "mod(~a,~a) = ~a   exact = ~a~%", t[1], t[2],
          mod(t[1],t[2]), mod(rationalize(t[1]),rationalize(t[2])))$
mod(1.0e15,3.0) = 1.0   exact = 1
mod(1.0e16,3.0) = 0.0   exact = 1
mod(1.0e17,3.0) = 0.0   exact = 1
mod(1.0e20,7.0) = 0.0   exact = 2
mod(-1.0e17,3.0) = 0.0   exact = 2
mod(1.0e17,-3.0) = 0.0   exact = -2

Expected: the float column should equal the exact column throughout.

The exact column applies mod to rationalize of the identical doubles, so it is the residue of exactly the numbers passed in. mod(1.0e15,3.0) is still correct, so the failure sets in around 1e16 and returns 0.0 from there on, for positive and negative arguments and for a negative modulus alike.

Discussion


Log in to post a comment.