## Odd RPGLE Multiplication issue

pts.
Tags:
Application development
RPGLE
I have a RPGLE program that traverses through a bill of materials to do a cost roll up. Part of the code multiplies several quantities together to get the quantity needed at that level. The multiplication is not yielding the correct answer and I?m not sure why. Below is a small sample program that illustrates the problem. Your help will be greatly appreciated?. Thanks D @1 s 15s 6 inz(1) D @2 s 15s 6 inz(1) D @3 s 15s 6 inz(1) D @4 s 15s 6 inz(1) D @5 s 15s 6 inz(4.900000) D @tqty s 15s 6 C C eval @tqty = (@1 * @5) C* this returns 4.900000 C* C eval @tqty = (((((@1 * @2) C * @3) * @4) C * @5)) C* this returns 4.000000 ? C* C eval *inlr = *on C return

## Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi Hoffman

I’ve seen this discussed before (on Midrange.Com I think) and it’s something to do with how the compiler interprets the EVAL statement with so many 15.6 length fields.

I can’t remember what the exact explanation was, but if you break the EVAL down into its component parts then everything works fine. E.g:

C Eval @tqty = @1 * @2
C Eval @tqty = @tqty * @3
C Eval @tqty = @tqty * @4
C Eval @tqty = @tqty * @5

Will give you the correct result.

All the best

Jonathan

## Discuss This Question: 3 Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
• That did the trick, thanks Jonathan, I appreciate your help.
0 pointsBadges:
report
• You have a bunch of fields with six fractional decimal positions. If you multiply two of those fields, an intermediate result must contain 12 fractional positions for accuracy. (Hint: what doues .000001 * .000001 = ?) If you multiply five such fields, then how many fractional positions must be maintained in an intermediate result? (5 * 6 = 30) If you work with fields that only hold 15 digits, how can you handle all of the necessary fractional positions? On which side of the decimal point should any accuracy be sacrificed? The problem isn't with the multiplication, it's how you have defined your fields and with insufficient understanding of what happens with fixed-point multiplication. It's working as defined in the language reference manual. Easiest resolution is the one you've chosen to use, but you might want to test with maximum and minimum values to ensure that everything will always work as expected. You didn't say anything about what version of the compiler you're using, so it's not clear how many fractional positions are available for you to work with. Tom
125,585 pointsBadges:
report
• Have you tried EVAL(R)?
8,225 pointsBadges:
report