$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [numeric::converter] finding the smallest c such that (a/c) + (b/c) < inf
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-03-21 17:39:45
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