Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Continued Fractions

Name: Anonymous 2007-09-03 14:57 ID:Yg9/l8CK

(defun continued-fraction (real)
  (multiple-value-bind (integer-part fractional-part)
      (floor (rationalize real))
    (cons integer-part (if (zerop fractional-part)
               nil
               (continued-fraction (/ 1 fractional-part))))))

What does /prog/ think? Am I shooting myself in the foot by just throwing rationalize in there and hoping it works out?

Name: Anonymous 2007-09-03 15:41 ID:Yg9/l8CK

>>9
Yeah, but to get results from a floating point input you've got to convert it to a rational... and if you divide out the fraction returned by that second function (written by someone other than OP, BTW), you'll get something other than the input that would make continued-fraction yield the continued fraction given to the second function.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List