Re: "Interesting" integer behavior

2010-03-12 Thread Rich Hickey
On Mar 10, 3:53 pm, Brian Hurt wrote: > In a recent clojure: > > user=> (class 2147483647) > java.lang.Integer > user=> (class (inc 2147483647)) > java.math.BigInteger > user=> (class (inc (inc 2147483647))) > java.lang.Long > user=> > > This isn't *technically* a bug, but it is an odd behavior.

Re: "Interesting" integer behavior

2010-03-11 Thread Mark Engelberg
If (inc 21471493647) and (+ 1 21471493647) produce different types of numbers, I would definitely categorize this as a "bug" and not just "strange behavior". This means that if you use 2147493748 as a key in a map or set it might work improperly depending on what computation you used to arrive at

Re: "Interesting" integer behavior

2010-03-11 Thread Stuart Campbell
I took a look at the code for Clojure 1.1, in clojure.lang.Numbers, and it seems that results of numerical ops on BigIntegers (BigIntegerOps) are passed to a 'reduce' method, which appears to return the most economical representation of a number: static public Number reduce(BigInteger val)

Re: "Interesting" integer behavior

2010-03-11 Thread Jürgen Hötzel
Hi, 2010/3/10 Brian Hurt : > In a recent clojure: > > user=> (class 2147483647) > java.lang.Integer > user=> (class (inc 2147483647)) > java.math.BigInteger upcasted to BigInteger because of overflow detection in IntegerOps, even though a cast to Long would be sufficient. Also odd because of: us

"Interesting" integer behavior

2010-03-10 Thread Brian Hurt
In a recent clojure: user=> (class 2147483647) java.lang.Integer user=> (class (inc 2147483647)) java.math.BigInteger user=> (class (inc (inc 2147483647))) java.lang.Long user=> This isn't *technically* a bug, but it is an odd behavior. Brian -- You received this message because you are subsc