ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%rem with zero

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

  • %rem with zero

    What happens if you use the %REM(n : 0)? modulo anything by 0 is always undefined right? I have a RPG program that is doing %REM(14 : 0) and returning a 2??? why is that? On some languages it's undefined or it returns the 14, since dividing by zero is undefined and everything is left over. Anyone??

  • #2
    On 7.1:
    %REM(n : 0) won't compile.
    If I use a variable with a 0 value, I get RNQ0102 (Attempt to divide by zero).

    Comment


    • #3
      tried a %REM(15 : 0), got 3...could it be because it's 00 instead of 0?


      which brings me to another noob questions: is the integer 01 same as 1 in rpg?
      Attached Files

      Comment


      • #4
        Integers 1 and 01 are the same (i.e. 1 = 01).

        If %REM(15 : 0) doesn't raise an error, check your PTF's. If it persists, call IBM.

        Comment


        • #5
          In the smaller images, there is a line of code before the %REM calculation, which is: IF ZccMod <> 00, so there is no way that the %REM calculation is executing when the value of ZccMod is zero. Could the source have been changed and not recompiled?

          Comment


          • #6
            It's also possible that the currently executing line is somewhere else in the program. So, even if the source matches the compiled object, the debug values might not be relevant to line 75. No way for us to know from what we can see.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment


            • #7
              About 01 vs 1, if you're thinking about octal values, RPG doesn't consider a number starting with zero to be an octal number. RPG only deals in decimal numbers. So 023 is twenty-three, the same as 23.

              For those not familiar with octal numbers in C or Java, if you start a number with a zero in C or Java (probably other languages too), the number is considered to be octal, base 8. So for example, 023 in C or Java is octal, so it means 2*8 + 3*1 = nineteen.

              Comment


              • #8
                Originally posted by Barbara Morris View Post
                For those not familiar with octal numbers in C or Java, if you start a number with a zero in C or Java (probably other languages too), the number is considered to be octal, base 8. So for example, 023 in C or Java is octal, so it means 2*8 + 3*1 = nineteen.
                Yet another reason to hate C & Java.

                But I am reminded of a joke. Why do programmers always mix up Halloween and Christmas?

                For the answer, click here: https://www.idtech.com/blog/part-i-t...he-rest-of-us/

                Comment

                Working...
                X