Hi Eric,

I tried to see what was going on with this calculation, knowing that when 
working with Java libraries which takes primitive type (as it is the cas 
with Math.pow)  this can be easily corrupted, which is the case in the *
probability-collision* fn
So , I think that Java lib cant be used.
Instead use Limited development.

In the probability-collision fn, 

exponent = 
9.18354961579912115600575419704879435795832466228193376178712270530013483949005603790283203125E-21M
(that is roughly 0.9E-21M)

So, *exp(*exponent) ~= 1 + exponent
and *(- 1M (/ 1M (.pow e exponent))) = (- 1M (/ 1M (+ 1 exponent))) = (- 1M 
(- 1M exponent)) = exponent*
*
*
and *probability-of-collision = exponent.*
*
*
This is beacause there is a truncation of the Java primitive type *double:*
*______________________________*
(let [imadeuapi 3.14159265358979323846264338327950288419716939937M]
(println (class imadeuapi))
imadeuapi)
; java.math.BigDecimal
;=> 3.14159265358979323846264338327950288419716939937M
_____________________________________________________
*The Joy of Clojure , section 4.1.1*
______________________________

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