HP3000-L Archives

October 2008, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
John Pitman <[log in to unmask]>
Reply To:
John Pitman <[log in to unmask]>
Date:
Wed, 15 Oct 2008 16:00:22 +1100
Content-Type:
text/plain
Parts/Attachments:
text/plain (49 lines)
And to make it plainer whats going on , do each operation in a single step, so you can debug it with display statements readily if the need arises.
In fact, split your compute up into discrete steps with a display stmt after each showing the intermediate results, and then do it again with the divide last, and check the differences out.

jp

-----Original Message-----
From: HP-3000 Systems Discussion [mailto:[log in to unmask]] On Behalf Of Walter J. Murray
Sent: Wednesday, 15 October 2008 3:48 PM
To: [log in to unmask]
Subject: Re: [HP3000-L] Cobol: Puzzled by results of COBOL Compute with and w/o Rounded option

Tony writes:

[snip]

> I don't understand why the LINE-ITEM-UNIT-PRICE and
LINE-ITEM-UNIT-COST
> yields the following results for this COMPUTE statement using ROUNDED

[snip]

> I'm not so concerned about why it is happening as much as how to make
it
> give the results I want.

The short answer is, when using a COMPUTE statement that involves
division, arrange the arithmetic expression so that the division will be
the last operation performed.

When you use a COMPUTE statement, you are throwing yourself on the mercy
of the compiler to decide how many decimal places to use for
intermediate results.  If you ever port this code to a different
platform or a different compiler, expect to get different results.

The safest, and most portable, technique is to avoid the COMPUTE
statement and stick with ADD, SUBTRACT, MULTIPLY, and DIVIDE.  Then you
get to control the precision of intermediate results, and the COBOL
language guarantees what the result will be.

Walter

Walter J. Murray

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2