Fork me on GitHub

Looking back at it, I don't get how (/ -9223372036854775808 -1) is not a bug, should I file a Jira or do something in ask Clojure?


(/ -9223372036854775808 -1)
=> -9223372036854775808
(/ -9223372036854775808M -1)
=> 9223372036854775808M
As a sidenote; Bignums work as expected


yes, they do fortunately. Other operations like these tend to fail (as would (inc 9223372036854775807) which would make sense


silently returning the wrong result feels wrong

Alex Miller (Clojure team)13:10:53

there are three families of arithmetic operations - overflow checked (the default), unchecked (via unchecked-ops and/or unchecked dynvar), and promoting (via op'). you say above "In most other cases there is a silent type promotion" - this is wrong. Automatic type promotion occurs when you have a mixture of types - then automatic widening promotion occurs, but that is not relevant here. This case is the default / operator, which has overflow check semantics. But, this case is overflowing and does not throw - why? This specific case is special in Java (and thus also in Clojure which is trying to surface the same safe, fast default Java behavior here). See says: > There is one special case that does not satisfy this rule: if the dividend is the negative integer of largest possible magnitude for its type, and the divisor is -1, then integer overflow occurs and the result is equal to the dividend. Despite the overflow, no exception is thrown in this case.

😮 2
🤯 2
Alex Miller (Clojure team)13:10:06

in general, per "where do I ask this question", it is always ok and preferred to ask it in - that allows other people to see it and answer it, the conversation to remain persistent (vs here, logging aside), and for me to track and log it as a jira if appropriate.


@alexmiller Yes right, I was wrong about silent promotion and got confused with old behavior.


In the meantime found out the same info in a different place:


@alexmiller Thanks about the confirmation anyway