|
|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 1079 (0x437)
Types: TextFile
Names: »FIB8087.PAS«
└─⟦505fbc898⟧ Bits:30002732 Turbo Pascal 5.0 for C-DOS Partner
└─⟦this⟧ »DEMOS\FIB8087.PAS«
æ Copyright (c) 1985, 88 by Borland International, Inc. å
æ$N+,E+å
program Fib8087;
æ
Sample program from P-335 in the Owner's Handbook that
demonstrates how to avoid 8087 stack overflow in recursive
functions that use the 8087 math co-processor. Local variables
are used to store temporary results on the 8086 stack.
å
var
i : integer;
function Fib(N : integer) : extended;
æ calculate the fibonacci sequence for N å
var
F1, F2 : extended;
begin
if N = 0 then
Fib := 0.0
else
if N = 1 then
Fib := 1.0
else
begin
(* Use this line instead of the 3 lines that follow this
comment to cause an 8087 stack overflow for values of
N >= 8:
Fib := Fib(N - 1) + Fib(N - 2); æ will cause overflow for N > 8 å
*)
F1 := Fib(N - 1); æ store results in temporaries on 8086 å
F2 := Fib(N - 2); æ stack to avoid 8087 stack overflow å
Fib := F1 + F2;
end;
end; æ Fib å
begin
for i := 0 to 15 do
Writeln(i, '. ', Fib(i));
end.
«eof»