64 bit arithmetic

Jit Keong Tan jit at SLIC.CELLBIO.DUKE.EDU
Wed Mar 13 04:00:16 AEST 1991


swanson at VANGOGH.BIOENG.WASHINGTON.EDU (Eric Swanson) says:
> Does anyone have/know of routines for 64 bit integer arithmetic

How about "(quote)
Integers may be up to b* ((1<<b) -1) bits long, where b is the number of bits
per short (typically 1048560 bits when b = 16).
" (close quote)

> for SG 4D or other MIPS based systems?
and possible all other type machines.

Does this sound good ?

Look no further but gnu c++ library, the Integer class library.
Sample output for tInteger class output:
Note: the numbers are not overflow !!


[226] jit % tInteger
one = 1
one + 1 = 2
two = 2
fact30 = factorial(30) = 265252859812191058636308480000000
fact28 = factorial(28) = 304888344611713860501504000000
fact30 + fact28 = 265557748156802772496809984000000
fact30 - fact28 = 264947971467579344775806976000000
fact30 * fact28 = 80872505331661933764010628483512781121876047953920000000000000

fact30 / fact28 = 870
fact30 % fact28 = 0
-fact30 = -265252859812191058636308480000000
lg(fact30) = 107
gcd(fact30, fact28) = 304888344611713860501504000000
sqrt(fact30) = 16286585271694955
negfact31 = -8222838654177922817725562880000000
fact30 + negfact31 = -7957585794365731759089254400000000
fact30 - negfact31 = 8488091513990113876361871360000000
fact30 * negfact31 = -2181131468794922353615366650200339706856997013317222400000
000000000
fact30 / negfact31 = 0
fact30 % negfact31 = 265252859812191058636308480000000
gcd(fact30, negfact31) = 265252859812191058636308480000000
fib50 = fibonacci(50) = 12586269025
fib48 = fibonacci(48) = 4807526976
fib48 + fib50 = 17393796001
fib48 - fib50 = -7778742049
fib48 * fib50 = 60508827864880718400
fib48 / fib50 = 0
fib48 % fib50 = 4807526976
gcd(fib50, fib48) = 1
sqrt(fib50) = 112188
pow64 = Ipow(2, 64) = 18446744073709551616
lg(pow64) = 64
s64 = 1 << 64 = 18446744073709551616
s32 = s64 >> 32 = 4294967296
comps64 = ~s64 = 18446744073709551615
comps64 & s32 = 4294967296
comps64 | s32 = 18446744073709551615
comps64 ^ s32 = 18446744069414584319

enter an Integer: 1092874219048723947239847
number = 1092874219048723947239847

End of test


--------------------------------------------------------
Jit Keong Tan     | internet: jit at slic.cellbio.duke.edu
(919) 684-8098    | bitnet  : tan00001 at dukemc.bitnet
--------------------------------------------------------
U.S. Mail:
Duke University Medical Center
Department Of Cell Biology
Box 3709
Nanaline Duke Bldg, Rm. 385
Durham, NC 27710



More information about the Comp.sys.sgi mailing list