
21 Mar
2009
21 Mar
'09
9:39 p.m.
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