IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help me to understand FLOAT strange behavior


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
anatol

Active User


Joined: 20 May 2010
Posts: 121
Location: canada

PostPosted: Thu May 20, 2010 6:52 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu May 20, 2010 6:59 pm
Reply with quote

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
View user's profile Send private message
anatol

Active User


Joined: 20 May 2010
Posts: 121
Location: canada

PostPosted: Thu May 20, 2010 7:17 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Try to understand IMS control block IMS DB/DC 0
No new posts Strange MNOTE related to BMS using PI... CICS 0
No new posts COBOL NOADVANCING strange results in ... COBOL Programming 4
No new posts To Understand EXECIO Read Parameter OPEN CLIST & REXX 2
No new posts Temp dataset unusual behavior JCL & VSAM 5
Search our Forums:

Back to Top