Clojure

Calculating large numbers results in java.math.BigIntegerArithmeticException

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • 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)

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/455
Hide
Assembla Importer added a comment -

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.

Show
Assembla Importer added a comment - 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.

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: