Overflow for Mod

Results 1 to 3 of 3

Thread: Overflow for Mod

  1. #1
    Vejas Guest

    Default Overflow for Mod

    Trying to determine the Modulus for a large number:<BR>Number1 = 8844633002<BR>Number2 = 50<BR>ModVal = CDbl(CDbl(Number1) Mod CDbl(Number2))<BR>Produces this error:<BR>Microsoft VBScript runtime error &#039;800a0006&#039; <BR>Overflow: &#039;[number: 8844633002]&#039; <BR>It seems like it is interpreting the number as Long but I have CDbl throughout. I do not understand. Is it the Mod ?<BR>tks for the help.

  2. #2
    Join Date
    Dec 1969

    Default Mod only works on 32-bit integers...

    From the docs:<BR><BR>** QUOTE **<BR>The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. <BR>** END QUOTE **<BR><BR>And I just looked at the C++ source code...yep, it only works for integers. Doubles are converted to 32-bit integers, and if they are too big, you get an error. <BR><BR>If you really need this, you could write your own function, no?<BR><BR>&#060;%<BR>Function DblMod( dbl1, dbl2 )<BR>&nbsp; &nbsp; DblMod = dbl1 - dbl2 * Round( dbl1/dbl2 )<BR>End Function<BR>%&#062;<BR><BR>Even that fails when the numbers get larger than a double can accurately represent. Around 14 decimal digits, or so.<BR><BR>

  3. #3
    Vejas Guest

    Default RE: Mod only works on 32-bit integers...

    Good Call ! <BR>I used your function DblMod, changed Round to Int and I get the same results as if I used Mod.<BR>tks,<BR>Vejas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts