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

  1. Newsgroups: comp.lang.c++
  2. From: nikki@trmphrst.demon.co.uk (Nikki Locke)
  3. Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
  4. Subject: Efficient 64-bit integer arithmetic
  5. Distribution: world
  6. Organization: Trumphurst Ltd.
  7. Lines: 28
  8. Date: Fri, 24 Jul 1992 10:04:18 +0000
  9. Message-ID: <711997458snx@trmphrst.demon.co.uk>
  10. Sender: usenet@gate.demon.co.uk
  11.  
  12. I need to implement efficient 64-bit signed integer arithmetic in C++ (or C)
  13. on a machine with a 32-bit long (actually, 60 significant bits + sign
  14. would do fine). 
  15.  
  16. I need addition, subtraction, multiplication, division, remainder, and 
  17. efficient multiply and divide by 10 (for conversion to/from strings).
  18.  
  19. I have looked at the bignum package, which implements arbitrary precision,
  20. but I feel the extra constraint of having only 60 significant bits should 
  21. enable a much more efficient implementation to be possible.
  22.  
  23. Does anyone know of any such code available for anonymous ftp ? Or have 
  24. any suggestions ?
  25.  
  26. I have a reasonably efficient add, subtract and multiply, (though no doubt
  27. some of the number theorists here could improve them significantly), but 
  28. the divide is currently accomplished by a full 64-bit rotate/subtract 
  29. loop, which I found much faster than the bignum method of estimating the 
  30. answer using floating point. This is almost certainly because I didn't 
  31. have an FP chip in my machine at the time, but I don't want to have to 
  32. insist on an FP chip for acceptable performance.
  33.  
  34. Thanks in advance,
  35.  
  36. ---
  37. Nikki Locke              |                        | nikki@trmphrst.demon.co.uk
  38. Trumphurst Ltd.          | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
  39. PC and Unix consultancy  | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
  40.