[Oberon] Fighting a dragon ...

Michael Schierl schierlm at gmx.de
Thu Jul 11 23:25:13 CEST 2024


Hello Hans,

Am 11.07.2024 um 18:40 schrieb Hans Klaver:

>   PROCEDURE Correct*;  (* TestDragon.Correct *)   (* correct result for x2 *)
>     VAR h, x1, x2: REAL;  s: INTEGER;
>   BEGIN
>     s := 0;  x1 := 7.499998E-01;
>     h := 2.500000E-01;
>     Out.String("s  = "); Out.Int(s, 2); Out.String("    h ="); Out.Real(h, 14); Out.Ln;
>     x2 := x1 + h * Math.cos( (FLT(s) - p/2.0) * pi/2.0 );  (* <-- expression tested *)
>     Out.String("x1 ="); Out.Real(x1, 14); Out.Ln;
>     Out.String("x2 ="); Out.Real(x2, 14); Out.Ln;
>     Out.Ln
>   END Correct;
>
>   PROCEDURE Incorrect*;  (* TestDragon.Incorrect *)   (* incorrect result for x2 *)
>     VAR h, x1, x2: REAL;  s: INTEGER;
>   BEGIN
>     s := 0;  x1 := 7.499998E-01;
>     h := Math.power(2.0, -p/2.0);  (* the result for h from Math.power() is correct: *)
>     Out.String("s  = "); Out.Int(s, 2); Out.String("    h ="); Out.Real(h, 14); Out.Ln;
>     x2 := x1 + h * Math.cos( (FLT(s) - p/2.0) * pi/2.0 );  (* <-- why incorrect result?? *)
>     Out.String("x1 ="); Out.Real(x1, 14); Out.Ln;
>     Out.String("x2 ="); Out.Real(x2, 14); Out.Ln;
>     Out.Ln
>   END Incorrect;


If you use Andreas' Out.Mod, you can see with Out.RealHex(h) what is
different. The "Correct" value is 3E80000H, while the "Incorrect" value
is slightly different. In Peter's floating point implementation, it is
3E7FFFFEH, while in mine (that piggybacks on my processor's native float
implementation) it is 3E7FFFFDH. Regardless which value, due to a bug in
Peter's floating point implementation, that different value ripples
through the multiplication.

The value of the multiplication before adding x1 (I called it x3) is

x3 = -1.250000E-01 BE000000H

in both Correct and Incorrect case for my floating point implementation,
while it is


x3 = -2.500000E-01 BE7FFFFDH

so almost double the value for the Incorrect case in Peter's
implementation. As the second factor is the same in both expressions,
the issue lies in the multiplication.

When at that point, I had a déjà-vu. A thread on this list started by
you in October 2023 ("Wrong results of selected REAL multiplications")
exactly discussed this issue. Did you fix that issue in your emulator/board?


Regards,


Michael


More information about the Oberon mailing list