View previous topic :: View next topic
|
Author |
Message |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
Hi All,
Could you please help me to understand FLOAT strange behavior. Here is code:
DCL AF FLOAT(15);
DCL AFL FLOAT(18);
AF = 6.66666666666;
AFL= 6.66666666666;
PUT SKIP DATA(AF,AFL);
IF AF = AFL THEN
PUT SKIP EDIT('ARE EQUAL')(A);
ELSE
PUT SKIP EDIT('ARE DIFFERENT')(A);
The output is for MVS PL/I:
AF= 6.66666666665999E+00 AFL= 6.66666666665999999E+00;
ARE DIFFERENT
The output for PLI Enterpize:
AF= 6.66666666666000E+00 AFL= 6.66666666666000000E+00;
ARE DIFFERENT
The questions are:
1.Why the AF and AFL are different - the value are the same
2. Is it possible to get the same result in PLI MVS and PLI Enterprize ( maybe some compile options) |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Floating point values are notorious for not comparing equally -- a single bit difference will keep the two values from being compared equally. Obviously, the difference between FLOAT(15) and FLOAT(18) is enough that the bits do not compare the same.
As far as I know, this behavior is true for all floating point variables -- whether in Assembler, PL/I, COBOL, or any other language you care to name. Equality of floating point variables is not usually tested for this reason. |
|
Back to top |
|
|
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
Thank you, Robert.
is it possible to get the same result ( AF & AFL compare was for test only) for MVS PLI and Ent PLI? maybe use special compiler options... The differencies are:
MVS PLI :
AF= 6.66666666665999E+00 AFL= 6.66666666665999999E+00;
Enterprize PLI:
AF= 6.66666666666000E+00 AFL= 6.66666666666000000E+00; |
|
Back to top |
|
|
|