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 integer overflow
clojure.lang.Numbers.throwIntOverflow (Num
bers.java:1374)

The optimization to using Longs seems to be too aggressive. Upgrade
casting in Clojure 1.2 is cool and simple.

Dominikus

On Sep 8, 1:30 pm, Eric Lavigne <lavigne.e...@gmail.com> wrote:
> 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/684fca15040e1ec8753429909b2...
>
> There are still some problems with this optimization, which will
> hopefully be worked out before the final 1.3 release.
>
>      http://dev.clojure.org/jira/browse/CLJ-836
>
>
>
>
>
>
>
> On Thu, Sep 8, 2011 at 6:25 AM, Dominikus <dominikus.herzb...@gmail.com> 
> wrote:
> > 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, [...].
> > """
> >http://dev.clojure.org/display/doc/Documentation+for+1.3+Numerics
>
> > However (type (- 2 1N)) results in java.lang.Long and does not seem to
> > work accordingly. What's going on here?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to