In Clojure 1.3, BigInts are said to be contagious across operations.
When different types of numbers are used in a math operation, the
result will be the larger or more general of the two types. For
example, any integer operation involving a BigInt will result in a
BigInt, [...].
You have discovered a very recent change. The idea is to automatically
switch to longs for performance when it is clear that overflow will
not occur.
https://github.com/clojure/clojure/commit/684fca15040e1ec8753429909b2d463e99d857e7
There are still some problems with this optimization,
Thanks, Eric. My original problem was the factorial function, which
breaks despite using BigInts:
user= (defn fact [n] (if (= n 1N) 1N (* n (fact (- n 1N)
#'user/fact
user= (type (fact 1))
clojure.lang.BigInt
user= (type (fact 20))
java.lang.Long
user= (type (fact 21))
ArithmeticException
Hi,
Am Donnerstag, 8. September 2011 13:57:49 UTC+2 schrieb Dominikus:
Upgrade casting in Clojure 1.2 is cool and simple.
It's also in 1.3 cool and simple.
user= (defn fact [n] (if (= n 1N) 1N (* n (fact (- n 1N)
#'user/fact
user= (fact 21)
ArithmeticException integer overflow
Even if you call the *correct* function recursively. *geez*
user= (defn fact' [n] (if (= n 1) 1 (*' n (fact' (dec n)
#'user/fact'
user= (fact' 21)
5109094217170944N
Sorry for the noise.
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups
Right, this feature is documented in
http://dev.clojure.org/display/doc/Documentation+for+1.3+Numerics
For me it feels somewhat strange to use primed operations to enforce
upgrade casting and to write a special faculty function for that.
I just discovered that (fact 21) breaks while (fact 21N)
Hi,
Am Donnerstag, 8. September 2011 14:21:09 UTC+2 schrieb Dominikus:
Right, this feature is documented in
http://dev.clojure.org/display/doc/Documentation+for+1.3+Numerics
For me it feels somewhat strange to use primed operations to enforce
upgrade casting and to write a special
Thanks for the explanation, Meikel!
I'll wait for the next release which hopefully fixes the bug.
Cheers,
Dominikus
On Sep 8, 2:31 pm, Meikel Brandmeyer (kotarak) m...@kotka.de
wrote:
Hi,
Am Donnerstag, 8. September 2011 14:21:09 UTC+2 schrieb Dominikus:
Right, this feature is
In Clojure 1.3, BigInts are said to be contagious across operations.
When different types of numbers are used in a math operation, the
result will be the larger or more general of the two types. For
example, any integer operation involving a BigInt will result in a
BigInt, [...].