Author: brent
Date: Sun Oct 9 01:24:15 2005
New Revision: 10258
Modified:
trunk/examples/shootout/pidigits.dylan
Log:
Job: 7045
Better version (thanks Peter and Bruce) using extended integers.
Works, but is slow).
Modified: trunk/examples/shootout/pidigits.dylan
==============================================================================
--- trunk/examples/shootout/pidigits.dylan (original)
+++ trunk/examples/shootout/pidigits.dylan Sun Oct 9 01:24:15 2005
@@ -1,6 +1,6 @@
module: pidigits
-use-libraries: common-dylan, io
-use-modules: common-dylan, standard-io, streams, format-out
+use-libraries: common-dylan, io, transcendental, dylan
+use-modules: common-dylan, standard-io, streams, format-out, extensions
/*
* Based on Christopher Neufeld's <shootout0000@xxxxxxxxxxx>
@@ -18,13 +18,13 @@
end function compose-val;
define function compute-pi ( *stop-digits*)
- let z = vector(1, 0, 0, 1);
- let $curstate = vector( 0, 2, 0, 1 );
+ let z = vector(#e1, #e0, #e0, #e1);
+ let $curstate = vector( #e0, #e2, #e0, #e1 );
- local method extract-digit (state, x :: <integer> ) => result :: <integer>;
- let numerator :: <single-float> = 1.0s0 * x * state[0] + state[1];
- let denominator :: <single-float> = 1.0s0 * x * state[2] + state[3];
- floor ( numerator / denominator );
+ local method extract-digit (state, x :: <integer> ) => result ::
<extended-integer>;
+ let numerator :: <extended-integer> = x * state[0] + state[1];
+ let denominator :: <extended-integer> = x * state[2] + state[3];
+ floor/ ( numerator, denominator );
end method extract-digit;
local method safe?( val, n ) => result :: <boolean>;
@@ -68,7 +68,6 @@
z := consume( z, next-state() );
end if;
end while;
- format-out("Ending\n");
end function compute-pi;
begin
--
Gd-chatter mailing list
Gd-chatter@xxxxxxxxxxxxxxxx
https://gauss.gwydiondylan.org/mailman/listinfo/gd-chatter
|