Pathological floating point problems: Difference between revisions

add PicoLisp
m (Phix/mpfr)
(add PicoLisp)
Line 2,757:
{t1,t2,t3,t4,t5,t6,t7} = mpfr_free({t1,t2,t3,t4,t5,t6,t7})</lang>
Identical output
 
=={{header|PicoLisp}}==
<lang PicoLisp>(scl 150)
(de task1 (N)
(cache '(NIL) N
(cond
((= N 1) 2.0)
((= N 2) -4.0)
(T
(+
(- 111.0 (*/ 1.0 1130.0 (task1 (- N 1))))
(*/
1.0
3000.0
(*/
(task1 (- N 2))
(task1 (- N 1))
1.0 ) ) ) ) ) ) )
(for N (list 3 4 5 6 7 8 20 30 50 100)
(println 'N: N (round (task1 N) 20)) )
 
# task 2
(setq B (- 2.7182818284590452353602874713526624977572470 1.0))
(for N 25
(setq B
(-
(* N B)
1.0 ) ) )
(prinl "bank balance after 25 years: " (round B 20))
 
# task 3
(de pow (A B) # fixedpoint
(*/ 1.0 (** A B) (** 1.0 B)) )
(de task3 (A B)
(let
(A2 (pow A 2)
B2 (pow B 2)
B4 (pow B 4)
B6 (pow B 6)
B8 (pow B 8) )
(+
(*/ 333.75 B6 1.0)
(*/
A2
(-
(*/ 11.0 A2 B2 (** 1.0 2))
B6
(* 121 B4)
2.0 )
1.0 )
(*/ 5.5 B8 1.0)
(*/ 1.0 A (*/ 2.0 B 1.0)) ) ) )
(prinl "Rump's example: " (round (task3 77617.0 33096.0) 20))</lang>
{{out}}
<pre>
N: 3 "18.50000000000000000000"
N: 4 "9.37837837837837837838"
N: 5 "7.80115273775216138329"
N: 6 "7.15441448097524935353"
N: 7 "6.80678473692363298394"
N: 8 "6.59263276870443839274"
N: 20 "6.04355211018926886778"
N: 30 "6.00678609303120575853"
N: 50 "6.00017584662718718895"
N: 100 "6.00000001931947792910"
bank balance after 25 years: 0.03993872967323020745
Rump's example: -0.82739605994682136814
</pre>
 
=={{header|Python}}==
298

edits