Re: [Boost-bugs] [Boost C++ Libraries] #12527: cpp_bin_float: Anal fixation. Part 3. Double rounding when result of convert_to<double>() is a subnormal

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12527: cpp_bin_float: Anal fixation. Part 3. Double rounding when result of convert_to<double>() is a subnormal
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-10-29 19:02:34


#12527: cpp_bin_float: Anal fixation. Part 3. Double rounding when result of
convert_to<double>() is a subnormal
-------------------------------+----------------------------
  Reporter: Michael Shatz | Owner: johnmaddock
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: multiprecision
   Version: Boost 1.62.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+----------------------------

Comment (by Michael Shatz):

 My code above produces wrong sign of zero at -(2!**-1075). Here is a fix:


 {{{
 double my_convert_to_double(const boost_quadfloat_t& x)
 {
   if (isnormal(x)) {
     if (x.backend().exponent() < -1023+1) {
       // subnormal or zero
       if (x.backend().exponent() < -1023 - 52) {
         return x.backend().sign() ? -0.0 : 0.0; // underflow
       }
       boost_quadfloat_t tmp = abs(x) + DBL_MIN;
       double res = tmp.convert_to<double>() - DBL_MIN;
       return x.backend().sign() ? -res : res;
     }
   }
   return x.convert_to<double>();
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12527#comment:2>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC