Thread: Messing with Large Integers

  1. #1
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186

    Messing with Large Integers

    Is there any set of functions that would allow easy manipulation of ULARGE_INTEGER's? Currently I'm trying to devise a way to handle the addition of one of these with a smaller number, handling overflow as the problem arises. Since a ULARGE_INTEGER is basically a collection of two DWORD's, the difficulty comes in detecting whether the smaller number added to the LowPart member is larger than the maximum DWORD value and adding the overflow to the HighPart member. I've constructed a code snippet that shows what I want to do:

    Code:
    ULARGE_INTEGER timeDifference;
    double newTimeLimit;
    DWORD maxDWORDValue;
    int someArbitraryValue;
    
    memset(&maxDWORDValue, 255, sizeof(DWORD));
    
    newTimeLimit = timeDifference.LowPart + someArbitraryValue;
    if (newTimeLimit > maxDWORDValue) {
       timeDifference.HighPart += newTimeLimit >> sizeof(DWORD);
    }
    
    timeDifference.LowPart += someArbitraryValue;
    Theoretically, if the addition of someArbitraryValue will overflow the LowPart member of the large integer, the result of the addition is shifted to the right by the size of a DWORD and added to the HighPart member to ensure that only the overflow amount is added to the high DWORD. The arbitrary value is then added to the LowPart member in either case under the assumption that any overflow would occur "quietly," causing LowPart to roll over as it should, but not affecting any other memory. Seem plausible?

    By the way, I can't use int64 because Dev-C++ doesn't recognize it as a built-in type.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  2. #2
    Does it support QWORD??
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  3. #3
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    No, QWORD's aren't supported.

    Alright, just found the ULONGLONG 64-bit Windows data type. Problem solved.
    Last edited by johnnie2; 11-16-2002 at 01:13 AM.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  4. #4
    I know you solved this but just for info sake, I think you would accomplish this with a sign BIT on the lowerpart.

    DWORD - 16bits
    0 000 0000 0000 0000 LOWPART
    ^
    sign Bit

    If the sign bit turns to 1 that would signal an overflow and then trigger some function to manage this.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. infinite looping when 2 large integers divide
    By Horse22 in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2005, 11:25 AM
  4. Replies: 6
    Last Post: 08-04-2003, 10:57 AM
  5. Storing large integers....why doesn't this work?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-21-2001, 09:41 PM