This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-05
Channels
- # beginners (46)
- # calva (89)
- # cider (24)
- # clara (7)
- # clj-kondo (36)
- # clojure (33)
- # clojure-australia (4)
- # clojure-dev (9)
- # clojure-europe (15)
- # clojure-israel (1)
- # clojure-nl (1)
- # clojure-uk (13)
- # clojurescript (55)
- # community-development (38)
- # conjure (1)
- # cryogen (12)
- # cursive (16)
- # data-science (4)
- # datomic (39)
- # events (2)
- # fulcro (5)
- # gorilla (3)
- # introduce-yourself (3)
- # jobs (9)
- # kaocha (5)
- # malli (16)
- # music (12)
- # off-topic (11)
- # polylith (4)
- # react (4)
- # reactive (1)
- # reagent (18)
- # remote-jobs (2)
- # reveal (2)
- # sci (4)
- # shadow-cljs (31)
- # timbre (4)
- # tools-build (70)
- # tools-deps (11)
- # vim (33)
- # xtdb (53)
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 expectedyes, they do fortunately. Other operations like these tend to fail (as would (inc 9223372036854775807)
which would make sense
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 https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17.2 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.
in general, per "where do I ask this question", it is always ok and preferred to ask it in http://ask.clojure.org - 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: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#floorDiv-long-long-
@alexmiller Thanks about the confirmation anyway