On Tue, Jun 26, 2012 at 1:11 AM, Sean Corfield <seancorfi...@gmail.com> wrote: > On Mon, Jun 25, 2012 at 9:19 PM, Cedric Greevey <cgree...@gmail.com> wrote: >> user=> 1e309 >> Infinity > > FWIW, on 1.4.0 I get: > > user=> 1e309 > CompilerException java.lang.RuntimeException: Unable to resolve > symbol: Infinity in this context, compiling:(NO_SOURCE_PATH:1)
That's *really* broken. Unfortunately, digging deeper I found that the 1023 exponent limit is 2^1023, not 10^1023, which means it really is around 309. I've had to reimplement some stuff using BigDecimals and to write these, since there seem to be no corresponding methods built into Java anywhere: (defn log [x] (if (instance? BigDecimal x) (let [s (.scale x)] (+ (Math/log (.scaleByPowerOfTen x s)) (* (- s) (Math/log 10.0)))) (Math/log x))) (defn log10 [x] (/ (log x) (Math/log 10.0))) (defn exp [x] (let [r (Math/exp x)] (if (.isInfinite r) (let [p10 (int (/ x (Math/log 10.0)))] (.scaleByPowerOfTen (bigdec (Math/exp (- x (* p10 (Math/log 10.0))))) p10)) r))) These seem to work fine, where extended precision isn't really needed, only large exponents. However, I've run into another problem, which is that when doubles and BigDecimals mix 1.3 seems to convert to doubles. This appears to contradict part of http://dev.clojure.org/display/doc/Documentation+for+1.3+Numerics specifically "When different types of numbers are used in a math operation, the result will be the larger or more general of the two types." That doesn't seem to hold when the types are double and BigDecimal, for some reason. Is there any setting I can change (analogous to with-precision) to force BigDecimal contagion? I considered using those icky primed operators, but for some reason /' seems to be missing from the set and I need division... -- 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