Continued fraction convergents

From Rosetta Code
Revision as of 23:19, 31 January 2024 by imported>CosmiaNebula (created page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Continued fraction convergents
You are encouraged to solve this task according to the task description, using any language you may know.

Given a positive real number, if we truncate its continued fraction representation at a certain depth, we obtain a rational approximation to the real number. The sequence of successively better such approximations is its convergent sequence.

Problem:

  • Given a positive rational number , specified by two positive integers , output its entire sequence of convergents.
  • Given a quadratic real number , specified by three positive integers , where is not a perfect square, output the first convergents when given a positive number .