Announcement

Collapse
No announcement yet.

Using MOD

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

  • Using MOD

    If I use MOD in Powerbasic (Dos) for the number of

    1960092520030605, I get 115.

    If I do the same thing in Lotus or Excel, I get 31 instead.

    Yes, I know R = Num1 MOD Num2 yields the remainder, but shouldn't
    the remainder be same no matter which application is doing the
    calculating? I am concerned I do not understand MOD as well
    as I had believed I did. I wonder if my number is too large for
    accuracy?

    Thanks.

    ------------------

  • #2
    What are you MOD'ing it by?


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      253

      ------------------

      Comment


      • #4
        What data type is your variable defined as?

        I tried using MOD(1960092520030605, 253) in ExcelXP and I get an error.

        I then tried the formula for MOD as such...1960092520030605 - (253 * INT(1960092520030605 / 253))
        In ExcelXP (in a single cell) and got 21. I also tried TRUNC instead of INT and got the same answer.

        I then tried the same formula step by step in a different cells.
        Code:
        1960092520030605 / 253 = 7747401264943.08
        253 * 7747401264943 = 1960092520030580 (!)
        1960092520030605 - 1960092520030580 = 20
        Using the same function above with Windows Calculator.
        Code:
        1960092520030605 / 253 = 7747401264943.102766798418972332
        253 * 7747401264943 = 1960092520030579
        1960092520030605 - 1960092520030579 = 26
        Using the below PB program (granted I tested under PBCC 3.02) I get the following...

        Code:
        FUNCTION PBMAIN
        	LOCAL a1 AS BYTE
        	LOCAL a2 AS INTEGER
        	LOCAL a3 AS WORD
        	LOCAL a4 AS LONG
        	LOCAL a5 AS DWORD
        	LOCAL a6 AS SINGLE
        	LOCAL a7 AS QUAD
        	LOCAL a8 AS DOUBLE
        	LOCAL lngModVal AS LONG
        
        	lngModVal = 253
        
        	a1=1960092520030605
        	a2=1960092520030605
        	a3=1960092520030605
        	a4=1960092520030605
        	a5=1960092520030605
        	a6=1960092520030605
        	a7=1960092520030605
        	a8=1960092520030605
        
        	PRINT a1 MOD lngModVal, a1 - (lngModVal * FIX(a1/lngModVal)), a1 - (lngModVal * INT(a1/lngModVal))
        	PRINT a2 MOD lngModVal, a2 - (lngModVal * FIX(a2/lngModVal)), a2 - (lngModVal * INT(a2/lngModVal))
        	PRINT a3 MOD lngModVal, a3 - (lngModVal * FIX(a3/lngModVal)), a3 - (lngModVal * INT(a3/lngModVal))
        	PRINT a4 MOD lngModVal, a4 - (lngModVal * FIX(a4/lngModVal)), a4 - (lngModVal * INT(a4/lngModVal))
        	PRINT a5 MOD lngModVal, a5 - (lngModVal * FIX(a5/lngModVal)), a5 - (lngModVal * INT(a5/lngModVal))
        	PRINT a6 MOD lngModVal, a6 - (lngModVal * FIX(a6/lngModVal)), a6 - (lngModVal * INT(a6/lngModVal))
        	PRINT a7 MOD lngModVal, a7 - (lngModVal * FIX(a7/lngModVal)), a7 - (lngModVal * INT(a7/lngModVal))
        	PRINT a8 MOD lngModVal, a8 - (lngModVal * FIX(a8/lngModVal)), a8 - (lngModVal * INT(a8/lngModVal))
        
        	WAITKEY$
        END FUNCTION
        Code:
        a1 =  141           141           141
        a2 =  240           240           240
        a3 =  240           240           240
        a4 = -167          -167           86
        a5 =  220           220           220
        a6 =  115           115           115
        a7 =  26            26            26
        a8 =  26            26            26
        ------------------
        Every day I try to learn one thing new,
        but new things to learn are increasing exponentially.
        At this rate I’m becoming an idiot faster and faster !!!
        ------------------
        George W. Bleck
        Lead Computer Systems Engineer
        KeySpan Corporation
        My Email



        [This message has been edited by George Bleck (edited June 05, 2003).]
        <b>George W. Bleck</b>
        <img src='http://www.blecktech.com/myemail.gif'>

        Comment


        • #5
          In PB/DOS I used:

          a&& = that number
          print;a&& mod 253 and got the result of 26.

          Just for larks, I then:
          print;a&& / 253 and received a remainder result of .10278

          Go figgure.

          Now, admittedly, we are dealing with a really big number and I'm
          sure there is an explaniation for this....
          ------------------


          [This message has been edited by Mel Bishop (edited June 05, 2003).]
          There are no atheists in a fox hole or the morning of a math test.
          If my flag offends you, I'll help you pack.

          Comment


          • #6
            Just for larks, I then:
            print;a&& / 253 and received a remainder result of .10278

            Go figgure.
            OK, Figgured.

            "/" does not create a 'remainder result.'

            Neither does "\" for that matter.

            Only MOD creates a 'remainder.'

            MCM

            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Dear all,
              the answer is 26.

              The number 1960092520030605 is too big to be correctly represented except as QUAD or EXT types so make sure you specify the right type.

              The line:
              PRINT 1960092520030605 MOD 253

              correctly prints 26 as the result in PBDOS3.5, PBCC1.0, UBASIC, and the numbers also work on Windows calculator in Win98se.

              Robert,
              you get 115 because you have assigned the number to a real (a!=..) which only holds about 7 digits.

              Mel,
              <<Go figgure.>>

              Go figure what? That's what you should get. 0.10278 * 253 = 26 as we'd expect.

              Paul.

              ------------------


              [This message has been edited by Paul Dixon (edited June 06, 2003).]

              Comment

              Working...
              X