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:46 ID:Heaven

>>1

I > U

(defun ensure-continued-fraction (real-number &aux (number (rationalize real-number)))
  (
multiple-value-bind (coefficient remainder) (floor number)
    (
cons coefficient (when (> remainder 0)
                        (
ensure-continued-fraction (/ remainder))))))


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