Ticket #6627: nonfinite_num_put_zero_formatting.patch

File nonfinite_num_put_zero_formatting.patch, 4.5 KB (added by krwalker@…, 11 years ago)
  • 3rdparty/Boost/boost/math/special_functions/nonfinite_num_facets.hpp

    diff --git a/3rdparty/Boost/boost/math/special_functions/nonfinite_num_facets.hpp b/3rdparty/Boost/boost/math/special_functions/nonfinite_num_facets.hpp
    index 8ee9170..286d109 100644
    a b namespace boost {  
    9999          if(flags_ & trap_infinity)
    100100            throw std::ios_base::failure("Infinity");
    101101          else if((boost::math::signbit)(val))
    102             put_num_and_fill(it, iosb, "-", "inf", fill);
     102            put_num_and_fill(it, iosb, "-", "inf", fill, val);
    103103          else if(iosb.flags() & std::ios_base::showpos)
    104             put_num_and_fill(it, iosb, "+", "inf", fill);
     104            put_num_and_fill(it, iosb, "+", "inf", fill, val);
    105105          else
    106             put_num_and_fill(it, iosb, "", "inf", fill);
     106            put_num_and_fill(it, iosb, "", "inf", fill, val);
    107107          break;
    108108
    109109        case FP_NAN:
    110110          if(flags_ & trap_nan)
    111111            throw std::ios_base::failure("NaN");
    112112          else if((boost::math::signbit)(val))
    113             put_num_and_fill(it, iosb, "-", "nan", fill);
     113            put_num_and_fill(it, iosb, "-", "nan", fill, val);
    114114          else if(iosb.flags() & std::ios_base::showpos)
    115             put_num_and_fill(it, iosb, "+", "nan", fill);
     115            put_num_and_fill(it, iosb, "+", "nan", fill, val);
    116116          else
    117             put_num_and_fill(it, iosb, "", "nan", fill);
     117            put_num_and_fill(it, iosb, "", "nan", fill, val);
    118118          break;
    119119
    120120        case FP_ZERO:
    121           if(flags_ & signed_zero) {
    122             if((boost::math::signbit)(val))
    123               put_num_and_fill(it, iosb, "-", "0", fill);
    124             else if(iosb.flags() & std::ios_base::showpos)
    125               put_num_and_fill(it, iosb, "+", "0", fill);
    126             else
    127               put_num_and_fill(it, iosb, "", "0", fill);
     121          if((flags_ & signed_zero) && ((boost::math::signbit)(val))) {
     122            put_num_and_fill(it, iosb, "-", 0, fill, val);
     123          } else {
     124            put_num_and_fill(it, iosb, 0, 0, fill, val);
    128125          }
    129           else
    130             put_num_and_fill(it, iosb, "", "0", fill);
    131126          break;
    132127
    133128        default:
    namespace boost {  
    137132        }
    138133      }
    139134
     135      template<class ValType>
    140136      void put_num_and_fill(
    141137        OutputIterator& it, std::ios_base& iosb, const char* prefix,
    142         const char* body, CharType fill) const
     138        const char* body, CharType fill, ValType val) const
    143139      {
    144         int width = (int)strlen(prefix) + (int)strlen(body);
     140        int prefix_length = prefix ? (int)std::strlen(prefix) : 0;
     141        int body_length = prefix ? (int)std::strlen(body) : 0;
     142        int width = prefix_length + body_length;
    145143        std::ios_base::fmtflags adjust
    146144          = iosb.flags() & std::ios_base::adjustfield;
    147145        const std::ctype<CharType>& ct
    148146          = std::use_facet<std::ctype<CharType> >(iosb.getloc());
    149147
    150         if(adjust != std::ios_base::internal && adjust != std::ios_base::left)
    151           put_fill(it, iosb, fill, width);
     148        if(body || prefix)
     149          if(adjust != std::ios_base::internal && adjust != std::ios_base::left)
     150            put_fill(it, iosb, fill, width);
    152151
    153         while(*prefix)
    154           *it = ct.widen(*(prefix++));
     152        if(prefix) {
     153          while(*prefix)
     154            *it = ct.widen(*(prefix++));
     155          iosb.width( iosb.width() - prefix_length );
     156          width -= prefix_length;
     157        }
    155158
    156         if(adjust == std::ios_base::internal)
    157           put_fill(it, iosb, fill, width);
     159        if(body) {
     160          if(adjust == std::ios_base::internal)
     161            put_fill(it, iosb, fill, width);
    158162
    159         if(iosb.flags() & std::ios_base::uppercase) {
    160           while(*body)
    161             *it = ct.toupper(ct.widen(*(body++)));
     163          if(iosb.flags() & std::ios_base::uppercase) {
     164              while(*body)
     165                *it = ct.toupper(ct.widen(*(body++)));
     166          }
     167          else {
     168            while(*body)
     169              *it = ct.widen(*(body++));
     170          }
     171
     172          if(adjust == std::ios_base::left)
     173            put_fill(it, iosb, fill, width);
    162174        }
    163175        else {
    164           while(*body)
    165             *it = ct.widen(*(body++));
     176          it = std::num_put<CharType, OutputIterator>::do_put(
     177            it, iosb, fill, val);
    166178        }
    167 
    168         if(adjust == std::ios_base::left)
    169           put_fill(it, iosb, fill, width);
    170179      }
    171180
    172181      void put_fill(