math
math copied to clipboard
`simple_continued_fraction`
Please provide this information in the documentation, it is available only in the source code:
// Deal with non-uniqueness of continued fractions: [a0; a1, ..., an, 1] = a0; a1, ..., an + 1].
// The shorter representation is considered the canonical representation,
Also, I am disappointed that I cannot acces particular coefficients of the continued fraction, so the whole class is useless in the case one does not want to use the provided public functions. I want to use it for rational approxamations. So I also need to convert it to rational afterwards.
This seems like a reasonable ask, and not too difficult. Lemme think about how to communicate it.
I added these member functions as a workaround:
size_t size() const noexcept { return b_.size(); }
const auto& operator [](int idx) const { return b_[idx]; }
auto& operator [](int idx) { return b_[idx]; }
void reserve(size_t size_) { b_.reserve(size_); }
void push_back(Z c) { b_.push_back(c); }
Although the non-const functions may cause inconsistency with the private member variable x_
, it seems that it is not used anywhere else than in the constructor (which suggests to actually remove the member variable and use only the parameter itself /or its local copy/).
Also, it is a question whether to check index bounds or not.