On Jul 20, 7:12 pm, Richard Newman <holyg...@gmail.com> wrote:
> > the return value is nil, i.e. no matching key found. I checked the
> > function that returns the lookup key. It works correctly.
>
> I don't see it:
>
> user=> ({0.05 "correct"} ((fn [] (+ 0.01 0.04))))
> "correct"
>
> Clojure has a sane idea of equality, so I suspect that numeric
> precision is the culprit. Can you post the function and its inputs
> that return 0.05?
Source:
(use '[clojure.contrib.math :only (expt round sqrt)])
(defn froundn [fnumber n]
"Round a float-number fnumber to n decimals"
(/ (round (* fnumber (expt 10 n))) (float (expt 10 n))))
(defn normality-u [n k p]
"Computes the value of substitute variable u (for lookup in table)"
(let [mu (* n p)
sigma (sqrt (* n p (- 1 p)))]
(/ (- k mu) sigma)))
The actual lookup then looks like this:
(normality-table (froundn (normality-u 500 51 0.1) 2))
I verified that (normality-u 500 51 0.1) yields 0.149..... and
(froundn (normality-u 500 51 0.1) 2) yields 0.15.
I suspect the float function call inside froundn to be the culprit in
that it changes the type of the number... but without this the result
would obviously be a ratio which is not what I want. And I dont know
how to test / modify it further.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---