[numeric::converter] finding the smallest c such that (a/c) + (b/c) < inf

Hi All,
template<typename T>
struct promote{};
template<>
struct promote<float> : mpl::identity<double>{};
template<>
struct promote<double> : mpl::identity<long double>{};
template<typename T> //T: float, double
struct fit_a_plus_b_to_range{
static T divider(T a, T b){
static const T mx = math::tools::max_value<T>();
static const T mi = math::tools::min_value<T>();
if(a > (mx - b)){
typedef typename promote<T>::type prom_t;
typedef numeric::converter

AMDG er wrote:
With delta = 0.0 the assertion fails, with delta = 1.0 it works (for a few examples). What's the smallest delta value? Is there a better way to do this overall?
This seems to work and the loops shouldn't be executed very many times. template<class T> T fit_to_range(const T& x, const T& y) { double max = (std::numeric_limits<T>::max)(); if(x > max - y) { double c = x/max + y/max; while(!boost::math::isinf(x/c + y/c)) { c = boost::math::float_prior(c); } while(boost::math::isinf(x/c + y/c)) { c = boost::math::float_next(c); } return(c); } else { return(static_cast<T>(1)); } } In Christ, Steven Watanabe

AMDG er wrote:
Steven Watanabe wrote:
template<class T> T fit_to_range(const T& x, const T& y) { double max = (std::numeric_limits<T>::max)();
Very helpful, thanks. May I ask : why double, not T?
cut and paste error. I was originally testing with plain doubles. In Christ, Steven Watanabe
participants (2)
-
er
-
Steven Watanabe