Template Function sequant::to_rational(T, T, std::size_t)

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 the sqrt of the machine epsilon for T; set to 0 to obtain exact representation of t as a rational number

  • max_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 of t