64-bit integer on a 32-bit machine 
Author Message
 64-bit integer on a 32-bit machine

I need to simulate 64-bit integers in C on a 32-bit platform.  I'm sure this
problem has been solved before but I haven't found any literature on it.  I
could work out a scheme using two 32-bit words and check for overflows, but
I was hoping for a more elegant solution.  Thanks in advance.


Thu, 22 May 2003 15:31:54 GMT  
 64-bit integer on a 32-bit machine
If you have a C99 compliant compiler...

Okay, so there are none, yet.  But if you have a compiler that
implements the long long type of C99, such as gcc, or, well, gcc, then
you can use that directly.
-*---*-------
Stephan T. Lavavej
http://quote.cjb.net



Thu, 22 May 2003 03:00:00 GMT  
 64-bit integer on a 32-bit machine

Quote:
>I need to simulate 64-bit integers in C on a 32-bit platform.  I'm sure this
>problem has been solved before but I haven't found any literature on it.  I
>could work out a scheme using two 32-bit words and check for overflows, but
>I was hoping for a more elegant solution.  Thanks in advance.

Many 32-bit platforms support 64-bit integers as an extension.  Check your
documentation.

long long is quite popular as a 64-bit integer.  It's even a standard C99
feature (C99 guarantees minimum 64 bits).

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Thu, 22 May 2003 03:00:00 GMT  
 64-bit integer on a 32-bit machine

Quote:
> I need to simulate 64-bit integers in C on a 32-bit platform.  I'm sure
this
> problem has been solved before but I haven't found any literature on it.
I
> could work out a scheme using two 32-bit words and check for overflows,
but
> I was hoping for a more elegant solution.  Thanks in advance.

The "Bible" for all such algorithms is D. Knuth's 'The Art of Computer
Programming' vol. 2. You can download the source code for an implementation
of multiple-precision integer arithmetic from Dr. Dobb's Journal
(http://www.ddj.com). Look for the source code for the August '92 issue.
Simplifying it to double-precision is left as an exercise for the reader.
:-)

Under C89, the only semi-portable solution is to combine two 32-bit
variables into one logical 64-bit variable, using standard
multiple-precision arithmetic. C99 mandates a 'long long' type which has at
least 64 bits of precision.

If you can accept a compiler-specific solution, many compilers have a 64-bit
integer type as an extension. See your compiler's documentation for details.

Daniel Pfeffer



Thu, 22 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. top 32 bits of 64-bit product of two 32-bit integers

2. REQUEST: 64-bit integer math on 32-bit processor

3. Looking for: multiply and divide of 32 bit integers (64 bit result)

4. Help: porting 32-bit app to 64-bit Dec Alpha

5. Calling 64 bit lib. from 32 bit program

6. emulating a 64 bit divide with 2 32 bit registers in ansi c

7. converting signed 64 bit - 32 bit

8. 64 bit operation on 32 bit PC

9. 64-bit chips, 32-bit compatibility?

10. Accessing 32-bit com componet from 64-bit application

11. 32-bit vs 64-bit

12. Tool 2 port 32 bit programms 2 64 bit

 

 
Powered by phpBB® Forum Software