× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On 31/01/2008, at 5:23 AM, Ala, Michael A wrote:

Question about MVR operation how should the Div Result be Defined with
or without decimals

Same for Remainder Field

MVR simply provides the remainder from the IMMEDIATELY preceding DIV operation. The remainder is simply what remains after the division operation has completed. The more decimal places you specify in the result of the DIV the smaller the remainder will be.


I have come up with various results with different formatting and want
to know best/Common practices

Example 60/84 = .714 on a calculator but one of programmers was not
getting this result with the move remainder when Both Fields were
defined with 3 decimal Places

0.714 is not the REMAINDER, it is the QUOTIENT. That is the number of times 84 will go into 60 is 0.714 (when accuracy to 3 decimal places is requested). This is the value you will get with division.

RPG calculates the remainder according to what is left over after the division operation. In your case if the quotient has 3 decimal places the remainder is 0.024. QED:

60 / 84 = 0.714
84 * 0.714 = 59.976
60 - 59.076 = 0.24

As you increase the accuracy of the quotient you decrease the magnitude of the remainder. RPG IV shows the results as:

60 / 84 = 0.714285
= 0.714285714
= 0.714285714285
= 0.714285714285714

Interesting pattern emerging here, don't you think? The remainder, of course, changes according to the accuracy of the previous division.


Should the DIV Be 0 Decimal and The remainder Be of x Decimals depending
on how precise you want the remainder to be

If you want the whole number remainder you must ensure the QUOTIENT has zero decimal places. The number of decimal places in the DIVIDEND, DIVISOR, and REMAINDER has no effect on the result.

I guess that most people expect integer division when MVR is involved but that's not how it works in practice.


Interestingly, in testing this I managed to blow up the translator:

MCH4229 Escape 40 31/01/08 08:23:49 VOXERROR 001318 QBNCRTMD QSYS *STMT
To module . . . . . . . . . : QBNCRTMD
To procedure . . . . . . . : main_module
Statement . . . . . . . . . : 951
Message . . . . : Dictionary entry not valid.
Cause . . . . . : The object was not created because the dictionary contains
an entry that is not valid. Recovery . . . : There is a problem in the
compiler. Report this problem to the supplier of the compiler. Technical
description . . . . . . . . : The reason code is 13. The index of the
dictionary entry that is not valid is 282, the dictionary entry is
X'0503000100000000000000000000002D00000011000000007000800080100000', and the
offset to the dictionary entry is 9044 bytes. The VLIC log note ID is
01018CC9.



Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.