home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / mcl / 1945 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  1.7 KB

  1. Path: sparky!uunet!stanford.edu!apple!cambridge.apple.com!bright@ENH.NIST.GOV
  2. From: bright@ENH.NIST.GOV
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: real to rational
  5. Message-ID: <01GT8C1NUVAQ003FX2@ENH.NIST.GOV>
  6. Date: 7 Jan 93 13:46:57 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 28
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. Does anyone have an algorithm that returns a rational approximation for a
  12. real number?
  13.  
  14. Many years ago, I saw a very simple iterative algorithm that ran on a HP
  15. desktop calculator.  For example, with an input of pi, the first iteration
  16. might have given a numerator of 22 and a denominator of 7.  The next
  17. iteration might give 157/50, etc.  Each iteration gave a more accurate
  18. approximation of the real, with larger and larger numerators and
  19. denominators.  The approximations were better than just chopping off
  20. digits:  3/1, 31/10, 314/100  etc.
  21.  
  22. My use for the algorithm would be to avoid floats in repetitive
  23. calculations.  For coordinate transformations, for example, it is
  24. convenient to calculate the rotation matrix using trig functions.  But
  25. then, I would like to convert the results to rationals (with the numerator
  26. and denominator separated) so that many points can be scaled and plotted
  27. quickly using integer arithmetic. {A good example of the integer arithmetic
  28. is the muldiv function (a*b/c) in thermometer.lisp, MCL2 examples folder. -
  29. Thanks to Bill St. Clair.}
  30.  
  31. Thanks 
  32. --Dave
  33. David S. Bright                        bright@enh.nist.gov  
  34. Microanalysis Research Group                                   
  35. National Institute of Standards & Technology (NIST, formerly NBS)
  36. Gaithersburg, MD 20899                                           
  37. USA
  38. 301-975-3911
  39.