Thread: octaword, double quadword

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    44

    octaword, double quadword

    on wikipedia i read about these types, but is it possible to declare and use them in C?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, but then it depends on what does octaword and double quadword actually correspond to. Maybe a long or long long will suffice, or you could use an arbitrary precision arithmetic library.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Octaword is 16 bytes, no (8 * 2)? There is no such type in C. So if you really need something that big, you'd have to either use an array or an arbitrary precision arithmetic library (whoa, thanks for that text, laserlight; I love copy n' paste!).
    I believe the standard says that long long is 8 bytes? Or does it only say that it's >= long?
    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.

  4. #4
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by Elysia View Post
    Octaword is 16 bytes, no (8 * 2)?
    Not strictly. Word size is architecture-specific. Hence not part of the standard. Hell, even byte size is defined as size of char.

    Quote Originally Posted by Elysia View Post
    I believe the standard says that long long is 8 bytes? Or does it only say that it's >= long?
    At least as big as long, yes.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I know word is machine specific, but I can't imagine it as less than 2 bytes
    So it is possible that long long can be 16 bytes, then. Though I think it is unlikely.
    So then it simply begs the question: what platform?
    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.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The 1999 edition of the C standard states that sizeof(long long) >= sizeof(long), and one can infer that the range of long long has a size of at least 64 bits.

    Quote Originally Posted by Elysia
    So it is possible that long long can be 16 bytes, then.
    Yes, if the range of long long was at least 128 bits in size.
    Last edited by laserlight; 07-07-2010 at 02:35 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    If you have a native 64-bit type, it isn't difficult to do 128-bit arithmetic. It does require some non-portable programming in order to detect carry conditions, but it's not complicated.

    Basically:

    Code:
    void AddOctWord( uint64 lo1, uint64 hi1, uint64 lo2, uint64 hi2, uint64 *loResult, uint64 *hiResult )
    {
        int carry;
        *loResult = lo1 + lo2;
        carry = GetCarryBit();
        *hiResult = hi1 + hi2 + carry;
    }
    The non-portable code is hidden inside GetCarryBit().

    Subtraction, multiplication, division are similar. For multiplication, realize that these numbers are of the form:

    lo+hi*2^64.

    Thus, the product of two 128-bit quantities is:

    (lo1+hi1*2^64)*(lo2+hi2*2^64)

    Using distributive law, the above is equal to:

    lo1*lo2 + lo1*hi2*2^64 + lo2*hi1*2^64 + hi1*hi2*2^128

    Factor it:

    (hi1*hi2)*2^128 + (lo1*hi2 + lo2*hi1)*2^64 + lo1*lo2

    Now the operations are all purely 64-bit. Just be aware that the first term can overflow if the quantities being multiplied have a geometric average greater than 2^64.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in printf line,,,what's wrong?
    By mft_ika in forum C Programming
    Replies: 9
    Last Post: 03-19-2010, 08:46 PM
  2. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 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