octaword, double quadword

This is a discussion on octaword, double quadword within the C Programming forums, part of the General Programming Boards category; on wikipedia i read about these types, but is it possible to declare and use them in C?...

  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
    21,452
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    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
    msh
    msh is offline
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    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
    21,452
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    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, 08: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, 05:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21