[fpc-pascal] real numbers infinity

Dimitrios Apostolou jimis at gmx.net
Tue Apr 11 01:45:11 CEST 2006


Hello list,

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.

example program:
> $ cat realover.pas
> program realover;
> Uses variants;
> var r:real;
> BEGIN
>         r:=2;
>         while True do
>         begin
>                 r:=r**2;
>                 writeLn(r);
>         end;
> END.

current output:
> $ ./realover
>  4.000000000000000E+000
>  1.600000000000000E+001
>  2.560000000000000E+002
>  6.553600000000000E+004
>  4.294967296000000E+009
>  1.844674407370955E+019
>  3.402823669209385E+038
>  1.157920892373162E+077
>  1.340780792994260E+154
> An unhandled exception occurred at $0805F1C6 :
> EInvalidOp : Invalid floating point operation
>   $0805F1C6
>   $0805F895
>   $08053CDF
>   $08048182

desired output:
>  4.000000000000000E+000
>  1.600000000000000E+001
>  2.560000000000000E+002
>  6.553600000000000E+004
>  4.294967296000000E+009
>  1.844674407370955E+019
>  3.402823669209385E+038
>  1.157920892373162E+077
>  1.340780792994260E+154
> inf
> inf
> inf
...


Thanks in advance,
Dimitris

P.S. Why when the program doesn't include the variants unit the program 
complains at runtime? What is that unit?



More information about the fpc-pascal mailing list