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

Inaccurate results with Round function


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

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Fri Sep 11, 2009 7:48 pm
Reply with quote

I am in a process of doing EPLI migration.
Can any one give solution for the below scenario

Code:
dcl x fixed dec(8);
dcl y fixed bin(31);
x=x+y;
z=round(x,2)


I have ended up s0ca (Fixed over flow) saying x is not in position to hold the value.
so I have changed like this

Code:
dcl x fixed dec(15);
dcl y fixed bin(31);
x=x+y
z=round(x,2)


but it is compilaton error as trying to do arithmetic operation with fixed bin(31) (variable y).

so I have changed
Code:
dcl x fixed bin(31)
dcl y fixed bin(31);
x=x+y
z=round(x,2)

but results were not accurate as they are using round function on x even I used dec builtin function like
below but ended up with inaccurate results.
Code:
dcl x fixed bin(31)
dcl y fixed bin(31);
x=x+y
z=round(dec(x),2)
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Fri Sep 11, 2009 8:14 pm
Reply with quote

Why would you round two integers?
Back to top
View user's profile Send private message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Fri Sep 11, 2009 9:15 pm
Reply with quote

Actually What I have given is just an example.
Infact it is like this
Code:
round((x/z)*100,2)
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Sep 11, 2009 9:24 pm
Reply with quote

COBOL has very precise rules governing intermediate results that are not immediately obvious to the casual observer. Maybe PL/I has similar rules?
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Fri Sep 11, 2009 9:50 pm
Reply with quote

Don't use fixed bin (31) for things they were not designed for.

They were designed as INTEGERs, don't use them for anything else, you'll rue the consequences.

And RTFM about the rules for mixing FIXED DEC and FIXED BIN.
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 Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts DB2 Statistics - Using EXPLAIN and qu... DB2 1
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
Search our Forums:

Back to Top