Pathological floating point problems: Difference between revisions

m
Adds Clojure solution, task 3
m (→‎Task 2: Chaotic Bank Society: fixing off-by-one error)
m (Adds Clojure solution, task 3)
Line 686:
Balance after 25 (rational representation):
1561042474970134/39085931702241241
</pre>
 
===Task 3: Rump's Example===
<lang clojure>(defn rump [a b]
(+ (* (rationalize 333.75) (expt b 6))
(* (expt a 2)
(- (* 11 (expt a 2) (expt b 2)) (expt b 6) (* 121 (expt b 4)) 2))
(* (rationalize 5.5) (expt b 8))
(/ a (* 2 b))))
; Using BigInt numeric literal style to avoid integer overflow
(double (rump 77617 33096N))</lang>
 
{{out}}
<pre>
-0.8273960599468214
</pre>
 
Anonymous user