Ticket #2390: floating_point_comparison.hpp.diff

File floating_point_comparison.hpp.diff, 1.6 KB (added by Jürgen Hunold, 14 years ago)

Improved patch for all gcc-4.3 warnings

  • boost/test/floating_point_comparison.hpp

     
    7979safe_fpt_division( FPT f1, FPT f2 )
    8080{
    8181    // Avoid overflow.
    82     if( f2 < static_cast<FPT>(1)  && f1 > f2*fpt_limits<FPT>::max_value() )
     82    if( (f2 < static_cast<FPT>(1))  && (f1 > f2*fpt_limits<FPT>::max_value()) )
    8383        return fpt_limits<FPT>::max_value();
    8484
    8585    // Avoid underflow.
    86     if( f1 == static_cast<FPT>(0) ||
    87         f2 > static_cast<FPT>(1) && f1 < f2*fpt_limits<FPT>::min_value() )
     86    if( (f1 == static_cast<FPT>(0)) ||
     87        ((f2 > static_cast<FPT>(1)) && (f1 < f2*fpt_limits<FPT>::min_value())) )
    8888        return static_cast<FPT>(0);
    8989
    9090    return f1/f2;
    9191}
    9292
     93// helper templates to prevent ODR violations
     94template<class T>
     95struct static_constant {
     96    static T value;
     97};
     98
     99template<class T>
     100T static_constant<T>::value;
     101
    93102//____________________________________________________________________________//
    94103
    95104} // namespace tt_detail
     
    221230};
    222231
    223232namespace {
    224 check_is_close_t check_is_close;
     233const check_is_close_t& check_is_close = tt_detail::static_constant<check_is_close_t>::value;
    225234}
    226235
    227236//____________________________________________________________________________//
     
    243252};
    244253
    245254namespace {
    246 check_is_small_t check_is_small;
     255const check_is_small_t& check_is_small = tt_detail::static_constant<check_is_small_t>::value;
    247256}
    248257
    249258//____________________________________________________________________________//