|
Boost Users : |
Subject: [Boost-users] [numeric::converter] finding the smallest c such that (a/c) + (b/c) < inf
From: er (erwann.rogard_at_[hidden])
Date: 2009-03-21 13:12:05
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<T,prom_t> up_t;
typedef numeric::converter<prom_t,T> down_t;
prom_t au = up_t::convert(a);
prom_t bu = up_t::convert(b);
prom_t mu = up_t::convert(mx);
prom_t cu = ((au/mu)+(bu/mu));
T delta = ...;
T c = down_t::convert(cu) + delta;
BOOST_ASSERT(!math::isinf((a/c)+(b/c)));
return c;
}else{
return (T)(1);
}
}
};
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?
If this is off topic, let me know...
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net