[fpc-pascal]Double-precision recursion

Rich Pasco pasco at acm.org
Fri Mar 30 00:52:37 CEST 2001


Sebastian Günther wrote:

> AFAIK, FPC works this way:
> 
> If you have a FPU operation which uses function results as arguments,
> such as
>   a := b + c(...);    (c is a function)
> then FPC will push 'b' on the FPU stack, call c() (which returns the
> result in the top-most FPU stack element), and add the both top-most
> elements.
> In the case of a recursion, you will get serious problems with this
> approach, of course.

I think you understand the problem perfectly.

> A workaround for  a := b + c(...);  is this: (might not work with
> optimizations enabled)
> 
>   var
>     d: Double;
>   begin
>     ...
>     d := c(...);
>     a := b + d;
>   end;

Indeed, that is how I have repaired my real application program, and
it seems to work correctly.  While that makes me happy, for now, I
still think that FPC should be fixed to avoid the problem with the
original source code.

I have updated my web page at
http://home.earthlink.net/~richpasco/pasbug.html
to reflect the state of this discussion so far.

     - Rich





More information about the fpc-pascal mailing list