连分数算法

来自GSXAB的知识库
连分数算法
术语名称 连分数算法
英语名称 continued fraction algorithm

连分数算法指把一个实数转化为连分数的算法。

算法

对给定实数 [math]\displaystyle{ a }[/math] ,有

  1. [math]\displaystyle{ i \leftarrow 0 }[/math]
  2. 令第 [math]\displaystyle{ i }[/math] 个部分商 [math]\displaystyle{ a_i = \lfloor a \rfloor }[/math]
  3. 计算 [math]\displaystyle{ a - a_i }[/math] ,如果为 0 终止循环
  4. 令第 [math]\displaystyle{ i+1 }[/math] 个完全商 [math]\displaystyle{ b_{i+1} = \frac{1}{a - a_i} }[/math]
  5. [math]\displaystyle{ a\leftarrow b_{i+1}, i \leftarrow i + 1 }[/math] ,回到第 2 步。


模板:连分数算法