Thread: double VS UINT64

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by Elysia View Post
    Actually, I just took a quick look at 0x7FFFFFFFFFFFFFFF (signed) and it looked equal to 2 ^ 63.
    Yes, but UINT64 is unsigned.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, I know. I didn't think of it then, but come to think of it now, of course it's 2 ^ 64, since a signed only has half the range.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by tabstop View Post
    It better not have; since it ends in 1 (binary), it must be odd. 2^63 would be even. That number would have 63 1's, so it should be 2^63 - 1. (And of course, max unsigned would be 0xFFFFFFFFFFFFFF, since we don't need the sign bit, which is 2^64 - 1.)
    As originally stated, the max UINT64 is 2^64-1, period.

    count1 = 98
    count2 = 2

    diff = 2-98 = -96
    actual diff = 4...But only if I know that the size of the counter is 100...and I don't know the size of the counter...
    Ah except you forgot one thing. The data types being used cannot represent negative numbers. In the theoretical case you gave, -96 would be represented as 4 in your unsigned type.
    A better example is where 255 is the max. Take finish = 5, start = 250. Finish-start = 5-250 = -245. Now lets put that into a byte. The lowest 8 bits are: 00001011. Viola that equals 10.

    Basically it is always safe to directly subtract two unsigned numbers that are based on a timer to get the correct answer. It only fails when the duration really does exceed the maximum value of the timer.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #19
    Registered User
    Join Date
    Dec 2007
    Posts
    49

    Exclamation

    Quote Originally Posted by iMalc View Post
    As originally stated, the max UINT64 is 2^64-1, period.

    Ah except you forgot one thing. The data types being used cannot represent negative numbers. In the theoretical case you gave, -96 would be represented as 4 in your unsigned type.
    A better example is where 255 is the max. Take finish = 5, start = 250. Finish-start = 5-250 = -245. Now lets put that into a byte. The lowest 8 bits are: 00001011. Viola that equals 10.

    Basically it is always safe to directly subtract two unsigned numbers that are based on a timer to get the correct answer. It only fails when the duration really does exceed the maximum value of the timer.
    Thank you ALL very very much!
    The best forum ever...(And a forum is made of a bunch of people...Appreciate it guys).

  5. #20
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Quote Originally Posted by iMalc
    The lowest 8 bits are: 00001011. Viola that equals 10.
    00001011 = 0x0B = 11

    Else, how i personaly see unsigned integer substraction, is "substract the 2 numbers and forget about the remaining burrow". Example

    Code:
        0 5
    -   F A
      1 1     // burrow line
      -----
        0 B
    You can also add the first term with the opposite of the second term. This is how processors implements substraction. Example

    Code:
        F A
        ---		// 15 complement
        0 5
        ---         // + 1 (Two complement)
        0 6
    
    
        0 5
    +   0 6
      -----
        0 B
    I'm just throwing out this extra information for people who could be interested.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  2. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  3. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 09:13 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM