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
 

 

Prevent rounding of COMP-2 when displayed

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sijayapal

New User


Joined: 23 Dec 2008
Posts: 69
Location: India

PostPosted: Wed Apr 08, 2015 10:07 pm    Post subject: Prevent rounding of COMP-2 when displayed
Reply with quote

Hello,

I came across a requirement to display comp-2 variables as external float. I used the edited picture clause to display the values. It works fine for values with small decimals. But if the value has more decimal values COBOL is rounding them.

I used the edit mask -9.9(14)E+99. IF the value is something like 1.23456999999999E+03 then it is getting converted to 1.23457000000000E+03.

Does COBOL rounds them by default? If so, could someone suggest me with any other alternative with SYNCSORT or Easytrieve?

Thanks,
Siva.
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Wed Apr 08, 2015 11:46 pm    Post subject: Reply to: Prevent rounding of COMP-2 when displayed
Reply with quote

Why do you think 1.23456999999999E+03 is your value?

To see what is happening, I'd suggest compiler option ARITH(EXTEND) and make your edit -9V29E+99.
Back to top
View user's profile Send private message
sijayapal

New User


Joined: 23 Dec 2008
Posts: 69
Location: India

PostPosted: Thu Apr 09, 2015 12:03 am    Post subject: Reply to: Prevent rounding of COMP-2 when displayed
Reply with quote

Quote:
Why do you think 1.23456999999999E+03 is your value?


That is what displayed in file manager when i browse the file with copybook layout.

Your question makes me to think if file manager is right?

I should try to decode the hex value to see what i get.

Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Thu Apr 09, 2015 3:04 am    Post subject:
Reply with quote

One thing you DEFINITELY need to be aware of is that different software products have different ways to handle floating point values. The different ways are not necessarily better -- or worse -- merely different. Assuming that COBOL is not right merely because File Manager gives you a different value is just as wrong as assuming that File Manager is not right because COBOL gives you a different value.

Also, some values, such as 0.1, cannot be expressed exactly as a binary value without using an infinite number of binary digits and hence such values will be an approximation when expressed as a floating point number on a computer. Hence for some values there is no way to avoid rounding them since they cannot be exactly expressed.

There are many valid reasons to use floating point variables. Expecting to be able to get precise numbers, however, is NOT one of those reasons.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Thu Apr 09, 2015 6:04 am    Post subject:
Reply with quote

This is what I found..... Take a break and see if you get an answer icon_smile.gif

Code:
It depends on the intermediate rounding and the final rounding set.

see this for more info :

D.13a Rounding

COBOL provides the capability of specifying rounding in arithmetic statements and expressions at various points in the evaluation process and as values are prepared for storing in receiving data items.

There are eight different forms of rounding supported by this standard:

• AWAY-FROM-ZERO: Rounding is to the nearest value of larger magnitude.

• NEAREST-AWAY-FROM-ZERO: Rounding is to the nearest value. If two values are equally near, the value with the larger magnitude is selected. This mode has historically been associated with the ROUNDED clause in previous versions of standard COBOL.

• NEAREST-EVEN: Rounding is to the nearest value. If two values are equally near, the value whose rightmost digit is even is selected. This mode is sometimes called “Banker’s rounding”.

• NEAREST-TOWARD-ZERO: Rounding is to the nearest value. If two values are equally near, the value with the smaller magnitude is selected.

• PROHIBITED: Since the value cannot be represented exactly in the desired format, the EC-SIZE-TRUNCATION condition is set to exist and the results of the operation are undefined.

• TOWARD-GREATER: Rounding is toward the nearest value whose algebraic value is larger.

• TOWARD-LESSER: Rounding is toward the nearest value whose algebraic value is smaller.

• TRUNCATION: Rounding is to the nearest value whose magnitude is smaller. This mode has historically been associated with the absence of the ROUNDED clause as well as for the formation of intermediate results in the prior COBOL standard.

The programmer may specify how individual intermediate values are rounded when they are stored into receiving data items through the ROUNDED clause; may select a default mode of rounding to be used when the ROUNDED clause appears with no further qualification on a receiving data item through the DEFAULT ROUNDED MODE clause of the OPTIONS paragraph of the IDENTIFICATION DIVISION; and may specify how arithmetic operations and conversions to and from intermediate forms are rounded through the INTERMEDIATE ROUNDING clause.

D.13a.1 Intermediate rounding

Intermediate rounding applies when data items are retrieved for inclusion in an arithmetic operation or arithmetic expression, and during the execution of arithmetic operators to produce an intermediate result.

In the previous standard, for multiplication and division in Standard Arithmetic, the default mode of rounding for inexact results was truncation to 32 significant digits. This default is unchanged in this standard, and is also the default for Standard-Binary and Standard-Decimal arithmetic.

When the intermediate value can be represented exactly in the appropriate intermediate format, the exact value is used.

In the event the value cannot be exactly represented, the user may also now specify other modes of rounding for arithmetic operations and for the conversions to and from intermediate forms used in the arithmetic operations through the optional INTERMEDIATE ROUNDING clause of the OPTIONS paragraph of the IDENTIFICATION DIVISION.

Specifically, the following options are available:

• INTERMEDIATE ROUNDING IS NEAREST-AWAY-FROM-ZERO • INTERMEDIATE ROUNDING IS NEAREST-EVEN • INTERMEDIATE ROUNDING IS PROHIBITED • INTERMEDIATE ROUNDING IS TRUNCATION

for which the subclause descriptions are found in D.13a, Rounding.

If the INTERMEDIATE ROUNDING clause is not specified, INTERMEDIATE ROUNDING IS TRUNCATION is presumed. This is unchanged from previous standards.

D.13a.2 Final rounding (the ROUNDED clause)

Final rounding applies to the formation of the final result of the expression or statement, at the completion of evaluation of the statement or expression, immediately before the result is placed in the destination. This form of rounding is that which is associated with the ROUNDED clause.

In previous COBOL standards, only two methods of “final” rounding were provided: rounding toward the smaller magnitude (truncation, signaled by the absence of the ROUNDED clause); and rounding to the nearest values, and if two values were equally near, choose the value with the larger magnitude (signaled by the presence of the ROUNDED clause).

The ROUNDED clause has been enhanced to allow explicit selection of any of eight modes of rounding (including the two previously available):

• ROUNDED MODE IS AWAY-FROM-ZERO • ROUNDED MODE IS NEAREST-AWAY-FROM-ZERO • ROUNDED MODE IS NEAREST-EVEN • ROUNDED MODE IS NEAREST-TOWARD-ZERO • ROUNDED MODE IS PROHIBITED • ROUNDED-MODE IS TOWARD-GREATER • ROUNDED MODE IS TOWARD-LESSER • ROUNDED MODE IS TRUNCATION

If the ROUNDED clause is not present for a given result, the rules for ROUNDED MODE IS TRUNCATION apply.

The optional DEFAULT ROUNDED MODE clause in the OPTIONS paragraph of the IDENTIFICATION DIVISION is provided to allow the user to specify the mode of rounding to any operation for which the ROUNDED clause appears without the MODE IS subclause.
 The DEFAULT ROUNDED MODE clause may take any of these forms:

• DEFAULT ROUNDED MODE IS AWAY-FROM-ZERO • DEFAULT ROUNDED MODE IS NEAREST-AWAY-FROM-ZERO • DEFAULT ROUNDED MODE IS NEAREST-EVEN • DEFAULT ROUNDED MODE IS NEAREST-TOWARD-ZERO • DEFAULT ROUNDED MODE IS PROHIBITED • DEFAULT ROUNDED MODE IS TOWARD-GREATER • DEFAULT ROUNDED MODE IS TOWARD-LESSER • DEFAULT ROUNDED MODE IS TRUNCATION

for which the subclauses of the DEFAULT ROUNDED MODE is clause are described in D.13a, Rounding.

If the DEFAULT ROUNDED MODE clause does not appear in the program, the effect of the ROUNDED clause without the MODE IS subclause is as if ROUNDED MODE IS NEAREST AWAY FROM ZERO had been specified. This provides the same functionality available in prior COBOL standards.

If the DEFAULT ROUNDED MODE clause appears, ROUNDED clauses without the MODE IS subclause are treated as if they had been specified with the rounding mode specified in the DEFAULT ROUNDED MODE clause.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Thu Apr 09, 2015 12:27 pm    Post subject: Reply to: Prevent rounding of COMP-2 when displayed
Reply with quote

Rohit,

That's for COBOL itself, I think first from the 2002 "Standard", now replaced by 2014.

Enterprise COBOL is to the 1985 Standard, with IBM Extensions, including things from 2002 (but not all) and some of their own things.

Rounding is only ever done when ROUNDED is explicitly specified.
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Need help to populate date in COMP-3 ... chetanambi DFSORT/ICETOOL 3 Tue Jun 21, 2016 12:25 pm
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm
No new posts SIGNED DECIMAL TO COMP-3 using cobol ... ram_vizag COBOL Programming 1 Tue Mar 01, 2016 11:32 pm


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