Template Function sequant::to_rational(T, T, std::size_t)¶
Defined in File rational.hpp
Function Documentation¶
-
template<typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
inline rational sequant::to_rational(T t, T eps = std::sqrt(std::numeric_limits<T>::epsilon()), std::size_t max_niter = 1000)¶ convert a floating-point number to a rational number to a given precision
- Parameters:
t – the floating-point number to convert
eps – the target precision, i.e. the largest permitted value of
T(result)-t
; the default is thesqrt
of the machine epsilon forT
; set to 0 to obtain exact representation oft
as a rational numbermax_niter – the maximum number of iterations to use to construct inexact representation by refining the Stern-Brocot tree (see https://mathworld.wolfram.com/Stern-BrocotTree.html)
- Returns:
the rational number within
eps
oft