![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Class template used to approximate decimal numbers by rationals. More...
#include <agrum/tools/core/math/rational.h>
Static Public Member Functions | |
Real approximation by rational | |
static void | farey (int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const int64_t &den_max=1000000L, const GUM_SCALAR &zero=1e-6) |
Find the rational close enough to a given ( decimal ) number in [-1,1] and whose denominator is not higher than a given integer number. More... | |
static void | continuedFracFirst (int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const double &zero=1e-6) |
Find the first best rational approximation. More... | |
static void | continuedFracBest (int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const int64_t &den_max=1000000) |
Find the best rational approximation. More... | |
Class template used to approximate decimal numbers by rationals.
GUM_SCALAR | The floating type ( float, double, long double ... ) of the number. |
Definition at line 58 of file rational.h.
|
static |
Find the best rational approximation.
Not the first, to a given ( decimal) number ( ANY number ) and whose denominator is not higher than a given integer number.
In this case, we look for semi-convergents at the right of the last admissible convergent, if any. They are better approximations, but have higher denominators.
numerator | The numerator of the rational. |
denominator | The denominator of the rational. |
number | The constant number we want to approximate using rationals. |
den_max | The constant highest authorized denominator. 1000000 by default. |
Definition at line 191 of file rational_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
static |
Find the first best rational approximation.
end of farey func
The one with the smallest denominator such that no other rational with smaller denominator is a better approx, within precision zero to a given ( decimal ) number ( ANY number).
It gives the same answer than farey assuming zero
is the same and den_max is infinite. Use this functions because you are sure to get an approx within zero
of number
.
We look at the semi-convergents left of the last admissible convergent, if any. They may be within the same precision and have a smaller denominator.
numerator | The numerator of the rational. |
denominator | The denominator of the rational. |
number | The constant number we want to approximate using rationals. |
zero | The positive value below which a number is considered zero. 1e-6 by default. |
Definition at line 94 of file rational_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
static |
Find the rational close enough to a given ( decimal ) number in [-1,1] and whose denominator is not higher than a given integer number.
Because of the double constraint on precision and size of the denominator, there is no guarantee on the precision of the approximation if den_max
is low and zero
is high. Prefer the use of continued fractions.
numerator | The numerator of the rational. |
denominator | The denominator of the rational. |
number | The constant number we want to approximate using rationals. |
den_max | The constant highest authorized denominator. 1000000 by default. |
zero | The positive value below which a number is considered zero. 1e-6 by default. |
Definition at line 35 of file rational_tpl.h.
References gum::Set< Key, Alloc >::emplace().