Thank you for your response, exactly what I was looking for. I knew I was 
missing something.

On Monday, July 2, 2012 5:55:49 AM UTC-7, Pierre-Henry Perret wrote:
>
> Hi Eric,
>
> The fundamental reason on that behaviour , is that Java Math library which 
> takes *double *as args, truncates its arguments, which is the case with 
> *Math.pow 
> .*
>
> From *The Joy of Clojure, sec. 4.1.1:*
> __________________________________________
> (let [imadeuapi 3.14159265358979323846264338327950288419716939937M]
> (println (class imadeuapi))
> imadeuapi)
> ; java.math.BigDecimal
> ;=> 3.14159265358979323846264338327950288419716939937M
> *BUT*
> (let [butieatedit 3.141592653589793*23846264338327950288419716939937*]
> (println (class butieatedit))
> butieatedit)
> ; java.lang.Double
> ;=> 3.141592653589793
> ______________________________________________
>
> So , I think the solution to your pb, seen that 
> *exponent = *
> 9.18354961579912115600575419704879435795832466228193376178712270530013483949005603790283203125E-21M
>
> is to do a limited development which leads to:
> *probabiblity-of-collision = exponent *
> when *number-of-decimal (exponent) > 15*
>
> HTH
>
> Le samedi 30 juin 2012 08:46:10 UTC+2, Eric Scrivner a écrit :
>>
>> Hey All,
>>
>> This is more than likely a newbie question, so my apologies if this is 
>> not directly clojure related.
>>
>> I'm not sure if this is a Java or Clojure specific issue, my guess is 
>> both. I'm trying to do some probability calculations with both very large 
>> and very small numbers. The function I'm using is as follows:
>>  
>>
>>> (defn probability-of-collision [num-unique, num-generated]
>>>
>>>   (let [exponent (.divide num-generated (.multiply 2M num-unique))]
>>>
>>>     (.subtract 1M (.divide 1M (.pow (bigdec java.lang.Math/E) 
>>>> exponent)))))
>>>
>>>
>> I would like to compute the answer for the following numbers, but only 
>> receive zero back:
>>
>> user=> (probability-of-collision (.pow 2M 132) (.pow 10M 20))
>>
>> 0M
>>
>>
>> I have tried using with-precision and several other approaches but cannot 
>> figure out how to get the correct value out. I was under the impression 
>> that BigDecimals support arbitrary precision arithmetic but perhaps I'm 
>> misunderstanding something? 
>>  
>>
>

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