Bug in clojure.core/mod with large Double argument

Description

The `clojure.core/mod` function works just as expected for small positive floating-point dividend and small positive integer divisor. But today I was working on some edge case tests and came across the following inexplicable behavior:

REPL_session

No idea whether this is inherited from a Java bug. I can see nothing special about the values chosen, and I suspect if one scanned it'd be easy to find other glitches.

Environment

Java 8 update 91 on Mac OS X 10.11.5

Activity

Show:
Alex Miller
June 15, 2016, 11:12 AM

mod is based on rem - from a glance, mod does not seem to account properly for any case of overflow, and I suspect that's at the root of a lot of these problems.

gfredericks
June 15, 2016, 11:15 AM

Test.check suggests (mod 6.7772677936779424E16 23) => -8.0 is somewhat close to minimal.

import
June 16, 2016, 4:40 AM

Comment made by: vaguery

Actually, just checked, and rem gives the same results. Thus (rem Double/MAX_VALUE 1001) is 1.9958403095347198E292, and (rem 6.7772677936779424E16 23) => -8.0.

Assignee

Unassigned

Reporter

import

Labels

Approval

Triaged

Patch

None

Affects versions

Priority

Major