Skip to main content

malachite_q/conversion/
traits.rs

1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::Rational;
10use malachite_nz::integer::Integer;
11use malachite_nz::natural::Natural;
12
13/// Returns a number's continued fraction.
14///
15/// The form of a continued fraction is $[a_0; a_1, a_2, a_3\ldots]$. The first component of the
16/// output pair is $a_0$, and the second is an iterator that produces the $a_i$ for $i > 0$.
17pub trait ContinuedFraction {
18    type CF: Iterator<Item = Natural>;
19
20    fn continued_fraction(self) -> (Integer, Self::CF);
21}
22
23/// Returns a number's convergents, as an iterator of [`Rational`]s.
24///
25/// The convergents of a real number are the rational numbers whose continued fractions are the
26/// prefixes of the original number's continued fraction.
27pub trait Convergents {
28    type C: Iterator<Item = Rational>;
29
30    fn convergents(self) -> Self::C;
31}