Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Help me to understand FLOAT strange behavior

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
anatol

Active User


Joined: 20 May 2010
Posts: 101
Location: canada

PostPosted: Thu May 20, 2010 6:52 pm    Post subject: Help me to understand FLOAT strange behavior
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: 7932
Location: Bellevue, IA

PostPosted: Thu May 20, 2010 6:59 pm    Post subject:
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: 101
Location: canada

PostPosted: Thu May 20, 2010 7:17 pm    Post subject: float values
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    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts CICS NEW SIT PARAMETERS CICS BEHAVIOR... Kyle Carroll CICS 0 Fri Nov 04, 2016 11:55 pm
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
No new posts DB2 FLOAT precision soundarr DB2 4 Fri Jul 15, 2016 9:47 pm
This topic is locked: you cannot edit posts or make replies. JCL to convert float decimal into rea... polymathtarun JCL & VSAM 3 Sun May 15, 2016 9:57 pm
No new posts Strange Results with ICETOOL Rohit Umarjikar DFSORT/ICETOOL 4 Tue Dec 22, 2015 4:12 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us