diff --git a/include/eve/module/contfrac/impl/lentz.hpp b/include/eve/module/contfrac/impl/lentz.hpp index e623e589ce..6e242aeb7d 100644 --- a/include/eve/module/contfrac/impl/lentz.hpp +++ b/include/eve/module/contfrac/impl/lentz.hpp @@ -92,7 +92,7 @@ namespace eve::detail using r_t = std::decay_t; using u_t = underlying_type_t; u_t tiny = 16*smallestposval(as()) ; - u_t terminator(eps <= 0 ? 16*eve::eps(as()) : u_t(eps)); + u_t terminator(eps <= 0 ? eve::abs(eps)*eve::eps(as()) : u_t(eps)); size_t counter(max_terms); r_t f{}; @@ -150,7 +150,7 @@ namespace eve::detail using r_t = std::decay_t; using u_t = underlying_type_t; u_t tiny = 16*smallestposval(as()) ; - u_t terminator(eps <= 0 ? 16*eve::eps(as()) : u_t(eps)); + u_t terminator(eps <= 0 ? eve::abs(eps)*eve::eps(as()) : u_t(eps)); size_t counter(max_terms); r_t f{}; diff --git a/include/eve/module/contfrac/lentz_a.hpp b/include/eve/module/contfrac/lentz_a.hpp index a2966aef4d..601e9e5c4a 100644 --- a/include/eve/module/contfrac/lentz_a.hpp +++ b/include/eve/module/contfrac/lentz_a.hpp @@ -28,35 +28,32 @@ namespace eve //! @code //! namespace eve //! { -//! template< typename Gen, eve::floating_value T> -//! T lentz_a(Gen g, const T& eps, size_t & max_terms) noexcept; +//! template< typename Gen, eve::scalar_ordered_value T> auto lentz_a(Gen g, const T& tol, size_t & max_terms) noexcept; //! } //! @endcode //! //! **Parameters** //! //! * `g` : generator function. -//! * `eps` : tolerance value. +//! * `tol` : tolerance value. If negative the effective tolerance will be abs(tol)*eve::eps(as(< u_t>) +//! where u_t is the underlying floating type associated to the return type of the invocable g. //! * `max_terms` : no more than max_terms calls to the generator will be made, //! -//! The generator type should be a function object which supports the following operations: -//! * Gen::result_type : The type that is the result of invoking operator(). -//! This can be either an arithmetic or complex type, -//! or a std::tuple of two floating values -//! * The call to g() returns an object of type Gen::result_type. -//! Each time this operator is called then the next pair of a and b values is returned. -//! Or, if result_type is not a pair type, then the next b value -//! is returned and all the a values are assumed to be 1. +//! The generator type should be an invocable which supports the following operations: +//! * The call to g() returns a floating value or a pair (kumi::tuple) of such. +//! Each time this operator is called then the next pair of a and b values has to be returned, +//! or, if result_type is not a pair type, then the next b value +//! has to be returned and all the a values are assumed to be equal to one. //! -//! * In all the continued fraction evaluation functions the tolerance parameter -//! is the precision desired in the result, -//! evaluation of the fraction will continue until the last term evaluated leaves -//! the relative error in the result less than tolerance. +//! * In all the continued fraction evaluation functions the effective tol parameter +//! is the relative precision desired in the result, +//! The evaluation of the fraction will continue until the last term evaluated leaves +//! the relative error in the result less than tolerance or the max_terms iteration is reached. //! //! **Return value** //! //! The value of the continued fraction is returned. -//! \f$\displaystyle \frac{a_1}{b_1+\frac{a_2}{b_2+\frac{a_3}{b_3+\cdots\vphantom{\frac{1}{1}} }}}\f$ +//! \f$\displaystyle \frac{a_0}{b_0+\frac{a_1}{b_1+\frac{a_2}{b_2+\cdots\vphantom{\frac{1}{1}} }}}\f$ //! //! @groupheader{Example} //! diff --git a/include/eve/module/contfrac/lentz_b.hpp b/include/eve/module/contfrac/lentz_b.hpp index aeda38e556..80865ca676 100644 --- a/include/eve/module/contfrac/lentz_b.hpp +++ b/include/eve/module/contfrac/lentz_b.hpp @@ -28,36 +28,38 @@ namespace eve //! @code //! namespace eve //! { -//! template< typename Gen, eve::floating_value T> -//! T lentz_b(Gen g, const T& eps, size_t & max_terms) noexcept; +//! template< typename Gen, eve::floating_value T> auto lentz_b(Gen g, const T& tol, size_t & max_terms) noexcept; //! } //! @endcode //! //! **Parameters** //! //! * `g` : generator function. -//! * `eps` : tolerance value. -//! * `max_terms` : no more than max_terms calls to the generator will be made, +//! * `tol` : tolerance value. If negative the effective tolerance will be abs(tol)*eve::eps(as(< u_t>) +//! where u_t is the underlying floating type associated to the return type of the invocable g. +//! * `max_terms` : no more than max_terms calls to the generator will be made. //! -//! The generator type should be a function object which supports the following operations: -//! * Gen::result_type : The type that is the result of invoking operator(). -//! This can be either an arithmetic or complex type, -//! or a std::tuple of two floating values -//! * The call to g() returns an object of type Gen::result_type. -//! Each time this operator is called then the next pair of a and b values is returned. -//! Or, if result_type is not a pair type, then the next b value -//! is returned and all the a values are assumed to be 1. +//! The generator type should be an invocable which supports the following operations: +//! * The call to g() returns a floating value or a pair (kumi::tuple) of such. +//! Each time this operator is called then the next pair of a and b values has to be returned, +//! or, if result_type is not a pair type, then the next b value +//! has to be returned and all the a values are assumed to be equal to one. //! -//! * In all the continued fraction evaluation functions the tolerance parameter -//! is the precision desired in the result, -//! evaluation of the fraction will continue until the last term evaluated leaves -//! the relative error in the result less than tolerance. +//! * In all the continued fraction evaluation functions the effective tol parameter +//! is the relative precision desired in the result, +//! The evaluation of the fraction will continue until the last term evaluated leaves +//! the relative error in the result less than tolerance or the max_terms iteration is reached. //! //! **Return value** //! //! The value of the continued fraction is returned. //! \f$\displaystyle b_0+\frac{a_1}{b_1+\frac{a_2}{b_2+\frac{a_3}{b_3+\cdots\vphantom{\frac{1}{1}} }}}\f$ //! +//! Note that the the first a value (a0) generated is not used here. +//! +//! @note the implementation is largely inspired by the boost/math/fraction one, with less requirements on the invocable. +//! Peculiarly lambda functions can be used. +//! //! @groupheader{Example} //! //! @godbolt{doc/polynomial/regular/lentz_b.cpp}