home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11532 < prev    next >
Encoding:
Text File  |  1992-07-25  |  1.7 KB  |  39 lines

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