Primary module interface unit for module continued_fraction.
More...
#include <vector>
import rational;
import base;
Primary module interface unit for module continued_fraction.
◆ nth_convergent_quadratic_irrational_cf()
template<Integer T>
| rational< T > ntlib::nth_convergent_quadratic_irrational_cf |
( |
std::size_t | n, |
|
|
const std::vector< T > & | cf ) |
|
export |
Computes the n-th convergent of the regular, periodic continued fraction for a quadratic irrational.
Algorithm from: http://mathworld.wolfram.com/PellEquation.html
- Parameters
-
| n | The n-th convergent is calculated. |
| cf | The continued fraction representation of the quadratic irrational. |
- Returns
- The numerator and denominator of the n-th convergent.
◆ quadratic_irrational_cf()
template<Integer T>
| std::vector< T > ntlib::quadratic_irrational_cf |
( |
const T & | n | ) |
|
|
export |
Continued fraction representation for a quadratic irrational.
Let \(n\) be a non-square natural number. This function template computes the continued fraction representation of \(\sqrt{n}\).
For non-squares (and only these) the continued fraction is regular and periodic.
- Template Parameters
-
- Parameters
-
| n | The number n. Must not be a perfect square. |
- Returns
- The regular, periodic continued fraction representing sqrt(n). The first position gives the whole number part, the second until the last one form the period.