home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Efficient 64-bit integer arithmetic
- Message-ID: <1992Jul25.145049.15951@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <711997458snx@trmphrst.demon.co.uk>
- Date: Sat, 25 Jul 1992 14:50:49 GMT
- Lines: 26
-
- In article <711997458snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
- >I need to implement efficient 64-bit signed integer arithmetic in C++ (or C)
- >on a machine with a 32-bit long (actually, 60 significant bits + sign
- >would do fine).
- >
- >I need addition, subtraction, multiplication, division, remainder, and
- >efficient multiply and divide by 10 (for conversion to/from strings).
- >
-
- Write one yourself. It is not so hard. There is (virtually)
- a whole book on it: Seminumerical Algorithms, by Knuth.
-
- Basically, do it like high school long division/multiply/
- add/subtract. To get the carry, do 16 bit operations with 32 bit
- result, the high 16 bits are the carry. You should be able to write
- add and subtract and multiply in about 1 hour. Division is a little harder,
- because as you know from high school you have to estimate the quotient
- digit, do a trial multiply and subtract, and the correct the estimate
- if you were wrong. Knuth give a good algorithm to improve the estimate.
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-