ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

What is the use of extenders R and M on Eval?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is the use of extenders R and M on Eval?

    Hi all,

    Why and when do we use Eval(R | M)?

    I heard is about precision on numeric operations but I can't understand what exactly it does. Can anyone explain and/or give an example?

    Thank you in advance

  • #2
    Good question. The docs aren't exactly clear.
    (M) Default precision rules
    (R) "Result Decimal Position" precision rules
    Check out the "Precision Rules for Numeric Operations" section in the RPG ref and see if that helps (it's page 6-61 in the 7.3 version I have).

    HTH

    Comment


    • #3
      The simple version is this. when an intermediate result has to be calculated (e.g. in an expression) the normal rules of math are used to determine what size that intermediate variable needs to be in terms of total length and decimal positions. But what if that requirement exceeds RPG's maximum capacity? A sacrifice has to be made - do you drop integer positions or decimal positions to make it fit? The obvious choice would be decimals, and that was the original behaviour of RPG (partly because I lost the argument).

      So the default of M - Max Digits means that the maximum number of integer positions is retained at the expense of decimal positions. Problem is that in expressions where there are multiple intermediate results it is very easy for decimal places to disappear completely. Due to many customer complaints about this, the R option (which was my original choice for the way it should work) was introduced R = Resulting Decimal Positions. What this means is that when digits are sacrificed, the number of decimal places is never allowed to drop below the number needed for the result.

      So if you have a 10.5 multiplied by a 15,0 the resulting temp should be 25,5. Assume for the sake of argument that the max is 20 digits. With the default the temp would be 20,0 - all decimals lost. With the R extender the temp would be 20,5. That theoretically increases the chances of overflow, but since it is rare for both fields to approach the maximum in the same calculation that will hardly ever happen. The example I usually give is that you might sell several thousand $1 items at a time, but you'll rarely sell a thousand $1M items at a time.

      With the increases in number of decimals that RPG can now handle, the need to use EVAL(R) is far less common that it used to be, but it can still be useful.

      If you still need more help then check out the manual which does a good job of explaining all the wrinkles in this.

      Comment


      • #4
        You can define this value globally too.


        CTL-Opt EXPROPTS(*RESDECPOS) // or *MAXDIGITS

        Ringer

        Comment

        Working...
        X