Menu

#601 Erroneous Arithmetic

v3.9.7
open
nobody
None
5
2024-05-28
2024-05-27
Walter
No

I noticed different results for a roseettacode task
https://rosettacode.org/wiki/Feigenbaum_constant_calculation
when running it with Regina and ooRexx
I found where the computations start to run differently

My test program:
Parse Version v; Say v
Numeric Digits 30
a=1.39699477705242943014290570625
Say 'a ='||a
x=0;
y=0
do 16
y=1-2xy
x=a-xx
end /
2*i/
a=a-x/y
Say 'x ='||x
Say 'y ='||y
Say 'x/y='||(x/y)
Say 'a ='||a

K:>rexx fct
REXX-ooRexx_5.1.0(MT)_64-bit 6.05 7 Feb 2023
a =1.39699477705242943014290570625
x =0.00029308138955703591412484758
y =5.95900277121112209566741518314
x/y=0.0000491829590972768327194163898515
a =1.39694559409333215331018628986

K:>regina fct
REXX-Regina_3.9.6(MT) 5.00 29 Apr 2024
a =1.39699477705242943014290570625
x =0.00029308138955703591412484765
y =5.95900277121112209566741519523
x/y=0.0000491829590972768327194164014987
a =1.39694559409333215331018628985

The difference grows with the number of iterations and ends up as

20 12 4.66920160910168137440902081266 115.921000 ooRexx
20 12 4.66920160910169069039564432665 337.176000 Regina
?
true value= 4.66920160910299067185320382047

ooRexx is apparently quite a bit faster in this case

1 Attachments

Discussion

  • Paul van den Eertwegh

    Hi Walter, I ran your program with 30 digits and 2 iterations giving

    REXX-Regina_3.9.6(MT) 5.00 29 Apr 2024
    a =1.39699477705242943014290570625
    x =-0.55459963005933757900129440937
    y =-1.79398955410485886028581141250
    x/y=0.309143176887707328204272488685
    a =1.08785160016472210193863321757

    REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
    a =1.39699477705242943014290570625
    x =-0.55459963005933757900129440936
    y =-1.79398955410485886028581141250
    x/y=0.309143176887707328204272488679
    a =1.08785160016472210193863321757

    Using 40 digits and 2 iterations I got
    x =-0.554599630059337579001294409364602341965
    for both Regina and ooRexx, showing that x should end in '0936'.
    Apparently the last digit(s) may differ between Regina (wrong) and ooRexx (better). And your program 'magnifies' the difference by each iteration. Even ooRexx drifts away from the true values while taking more iterations.

    This shows the pitfalls of numerical calculations. Always beware of precision loss, take enough digits in your programs.

     
  • Walter

    Walter - 2024-05-27

    This ain't the problem-
    Regina and ooRexx (and other Rexxes) should give the same results!

     
  • Paul van den Eertwegh

    Okay! In this case then, Regina doesn't always correctly round the numbers to the digits setting.
    Such as
    say 10/6 gives correct 1.66666667 with the default 9 digits (meaning internally at least 1 extra digit was taken into account).

     
    • Walter

      Walter - 2024-05-27

      But that is correct
      Say 10/6
      Numeric Digits 10
      Say 10/6

      K:>rexx 106
      1.66666667
      1.666666667
      K:>regina 106
      1.66666667
      1.666666667

       
  • Paul van den Eertwegh

    Using the original Rosettacode program and 'trace results' I succeeded in creating a small example.
    Consider following code snippet:

    numeric digits 9
    x = 1.38154750
    say x*x

    Regina produces
    1.90867350
    and ooRexx
    1.90867349

    On a 12-digit calculator I get
    1.90867349476

    Both the ooRexx manual and the Standard state that results should be rounded to the number of numeric digits. So Regina is in error here!

     

Log in to post a comment.