BigInt + 0.5 = Infinity?

2010-10-08 Thread Miki
If the following intentional?

user= (defn fact [n] (reduce * 1 (range 1 (inc n
#'user/fact
user= (fact 1000)
402387260077093773543702433923003985719374864210714632543799910...
user= (+ 0.5 (fact 1000))
Infinity

-- 
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


Re: BigInt + 0.5 = Infinity?

2010-10-08 Thread Per Vognsen
Sure. BigInteger.doubleValue() casts to infinity if the value is too
large to be represented:

user (double (fact 1000))
Infinity

You could try this using BigDecimals instead of doubles:

user (+ 0.5M (fact 1000))

-Per

On Sat, Oct 9, 2010 at 11:08 AM, Miki miki.teb...@gmail.com wrote:
 If the following intentional?

 user= (defn fact [n] (reduce * 1 (range 1 (inc n
 #'user/fact
 user= (fact 1000)
 402387260077093773543702433923003985719374864210714632543799910...
 user= (+ 0.5 (fact 1000))
 Infinity

 --
 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

-- 
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