<< Back to previous view

[CLJ-455] Calculating large numbers results in java.math.BigIntegerArithmeticException Created: 08/Oct/10  Updated: 23/Oct/10  Resolved: 23/Oct/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: Backlog

Type: Defect
Reporter: Anonymous Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None


 Description   

(class (* 1000 1000 1000 1000 1000 1000 1000))
1.1 returns : java.math.BigInteger
1.3.0-alpha returns : java.math.BigIntegerArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1575)



 Comments   
Comment by Assembla Importer [ 23/Oct/10 10:52 PM ]

Converted from http://www.assembla.com/spaces/clojure/tickets/455

Comment by Assembla Importer [ 23/Oct/10 10:52 PM ]

ataggart said: This is correct behavior with respect to 1.3.0 (yes, it's a breaking change).

If one wants to allow numbers larger than what fits in a long to flow out of math ops, one needs to explicitly start with a BigInt:

user=> (type 1N)
clojure.lang.BigInt
user=> (class (* 1000N 1000N 1000N 1000N 1000N 1000N 1000N))
clojure.lang.BigInt</code></pre>
If one wants to allow autopromotion, one can use the new "tick" math ops:
<pre><code>user=> (class (*' 1000 1000 1000 1000 1000 1000 1000))
clojure.lang.BigInt

NB: Rich suspects almost no one should need these ops, and if you think you do, you're probably wrong.

Generated at Tue Sep 30 11:22:57 CDT 2014 using JIRA 4.4#649-r158309.