[fpc-pascal] real numbers infinity
Sasa Zeman
public at szutils.net
Tue Apr 11 07:37:07 CEST 2006
Dimitris,
> when a real number overflows the program halts with EInvalidOp error.
> How can I make the program behave the more standard way, where the
> variable gets the value "inf" and execution continues normally? This is
> vital for many tasks, like fractal computation.
You can use try..except..end block and switch -Sd when compile:
program realover;
Uses math;
var r:real;
BEGIN
r:=2;
while True do
begin
try
r:=r**2;
writeLn(r);
except
r:=infinity;
writeLn(r);
// break
end;
end;
END.
Or you may take a look IEEE specification if it is necessary to create your
own big float support for larger precision with fractals.
> P.S. Why when the program doesn't include the variants unit the program
> complains at runtime? What is that unit?
At windows, it is not necessary for this example. Variants unit provide new
type definition and supported functions, which can consist any simple type
(integer, string, etc).
Sasa
More information about the fpc-pascal
mailing list