View previous topic :: View next topic
|
Author |
Message |
ashutosh.pr
New User
Joined: 13 Apr 2007 Posts: 36 Location: Pune
|
|
|
|
Hi,
I just encountered this while starting to learn REXX.
I run the same script on the mainframes after putting it in a PDS member and separately in a notepad using Regina interpreter.
The script is:
/* REXX */
A = '125' ; B = '125' ;
NUMERIC FORM SCIENTIFIC
prod = A ** B;
SAY prod;
I get the following results:
Mainframes:
1.29942622E+262
Regina:
1.29942623E+262
Anyone aware of this issue and the probable reason for this?
Thanks,
Ashutosh |
|
Back to top |
|
|
mtaylor
Active User
Joined: 20 Feb 2009 Posts: 108 Location: Kansas City
|
|
|
|
Clearly you're assuming floating point arithmetic is standard across machines and it isn't. So, the same operation does not give the same answer on two different machines and you have no right to expect it to. Adoption of floating point standards has been a contentious issue over the years. Nowadays, IEEE 754 is becoming the defacto 'standard' and it's welcome. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Mainframe is right, Regina is very wrong.
Code: |
Expression: 125**125
Result : 1.299426220705612402316300572585238295973692851047E+262 |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Have you ever studied precision and accuracy of numerical computations in any course? If so, you should not be surprised by these results.
A simple test is to set up a COMP-2 field in a COBOL program, set it to 1 and multiply it by each integer from 2 to 30. Repeat the test starting at 30 and going down to 1. You will find the displayed results are not the same even though mathematically the exact same computations are being done.
Mathematics implies, at times, infinite number of digits for numbers. Computers do not handle infinite numbers of digits, so the results returned by a given set of mathematical operations (1) may be affected by the order in which computations are done, and (2) may or may not resemble the mathematical result. This applies even more when dealing with different platforms or even different compilers / interpreters on a single platform. |
|
Back to top |
|
|
ashutosh.pr
New User
Joined: 13 Apr 2007 Posts: 36 Location: Pune
|
|
|
|
Thank you all! |
|
Back to top |
|
|
|