Results 1 to 6 of 6

Thread: Finding the MOD of a large number

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    8

    Question

    I'm writing a routine which requires the handling of large numbers.

    I've declared all my variables as Variant and I use CDec where required.

    However, I get an Overflow Error (6) when I use the MOD operator.It seems to be restricted to Long data-types.


    Is there an equivalent I can use, or am i using it incorrectly?

    Thanks,



    Jim

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    What size numbers are you using?

    Using Variants is usually a bad idea
    Mark
    -------------------

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Talking

    Code:
    a mod b
    is the same thing as
    Code:
    a - Int(a / b) * b
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    8

    Exclamation

    VERY large numbers!

    I've had to use variants in order to use the Decimal sub-type - that's how big they are.

    In the order of 1,000,000,000,000,000,000,000

    The help file doesn't indicate that MOD is restricted to the LONG range, but that would appear to be the case.

    Any APIs?....



  5. #5
    New Member Bill Gates's Avatar
    Join Date
    Mar 2000
    Posts
    7

    Thumbs up

    jimwillsher is working on a "bank account" calculator for me

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    8
    Sorted it!

    Looks like the MOD calculator is limited to the LONG range, but the INT operator is not.

    Changed logic to use

    Dim Whole as Variant

    Whole = CDec(Int(Long_Number / Divisor))

    Remainder = Long_number - (Whole * Divisor)



    Seems to work fine now - handles the full range of DECIMAL numbers.

    (For reference, I'm writing a base-conversion utility and need to be able to handle extremely long hex numbers. My numbers ar enot restricted to just Hex, therefore I can;t use any of the built-in functions.)

Posting Permissions

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



Click Here to Expand Forum to Full Width