|
From: Jeffrey Walton on 31 Jan 2010 13:23 Hi All, I'm looking at some code that is seg faulting while attempting to perform a divide using a 64 bit dividend and divisor. The code is written without a native 64 bit word, so: struct MY_INT_64 { int32 high; // signed uint32 low; // unsigned } The code is generalized using Knuth's algorithm from AOCP (Volume 2, p. 273). I think the best way to proceed is to use a canned implementation specialized for 32 bit word sizes rather than vet out the problems with the generalized implementation. Does anyone have a C/C++ implementation for 64 bit division using two 32 bit registers? I only need the quotient, but I'll take something that computes both q and r. Thanks, JW
From: Ilmari Karonen on 31 Jan 2010 13:51 On 2010-01-31, Jeffrey Walton <noloader(a)gmail.com> wrote: > > Does anyone have a C/C++ implementation for 64 bit division using two > 32 bit registers? I only need the quotient, but I'll take something > that computes both q and r. Your C compiler might have one. Are you sure it doesn't provide a 64-bit integer type? (Try int64_t from stdint.h.) -- Ilmari Karonen To reply by e-mail, please replace ".invalid" with ".net" in address.
From: Jeffrey Walton on 31 Jan 2010 15:08 Hi Ilmari, > > Does anyone have a C/C++ implementation for 64 bit division using two > > 32 bit registers? I only need the quotient, but I'll take something > > that computes both q and r. > > Your C compiler might have one. Are you sure it doesn't provide a > 64-bit integer type? (Try int64_t from stdint.h.) > I took a look at the current implementation and stdint. I believe the problem is compiler, conformance, platform, and portability - some compilers on Win32 might not have __UINT64_C and __INT64_C. JW
From: Tim Little on 31 Jan 2010 20:02 On 2010-01-31, Jeffrey Walton <noloader(a)gmail.com> wrote: > Does anyone have a C/C++ implementation for 64 bit division long long int a, b, x; ... x = a/b; - Tim
From: Jeffrey Walton on 1 Feb 2010 07:50 Hi Tim, On Jan 31, 8:02 pm, Tim Little <t...(a)little-possums.net> wrote: > On 2010-01-31, Jeffrey Walton <noloa...(a)gmail.com> wrote: > > > Does anyone have a C/C++ implementation for 64 bit division > > long long int a, b, x; ... x = a/b; I believe 'long long' makes an assumption that the size is 64 bits, which might not be the case on all platforms (some Win32 stuff comes to mind). From reading on the project, it looks like the only premise is a 32 bit data type exists. JW
|
Next
|
Last
Pages: 1 2 Prev: What makes a trivial operator trivial ? Next: May empty entire math departments |