Exemple #1
0
 //! returns -1, 0, 1, or 2 if 'this' is <, ==, >, or 'nan comparison' rhs
 int compare(const int_adapter& rhs)const
 {
   if(this->is_special() || rhs.is_special())
   {
     if(this->is_nan() || rhs.is_nan()) {
       if(this->is_nan() && rhs.is_nan()) {
         return 0; // equal
       }
       else {
         return 2; // nan
       }
     }
     if((is_neg_inf(value_) && !is_neg_inf(rhs.value_)) ||
        (is_pos_inf(rhs.value_) && !is_pos_inf(value_)) )
       {
         return -1; // less than
       }
     if((is_pos_inf(value_) && !is_pos_inf(rhs.value_)) ||
        (is_neg_inf(rhs.value_) && !is_neg_inf(value_)) ) {
       return 1; // greater than
     }
   }
   if(value_ < rhs.value_) return -1;
   if(value_ > rhs.value_) return 1;
   // implied-> if(value_ == rhs.value_) 
   return 0;
 }
Exemple #2
0
 //! Returns either special value type or is_not_special
 static special_values to_special(int_type v)
 {
   if (is_not_a_number(v)) return not_a_date_time;
   if (is_neg_inf(v)) return neg_infin;
   if (is_pos_inf(v)) return pos_infin;
   return not_special;
 }
Exemple #3
0
 inline
 int_adapter operator-(const int_adapter<rhs_type>& rhs)const
 {
   if(is_special() || rhs.is_special())
   {
     if (is_nan() || rhs.is_nan()) 
     {
       return int_adapter::not_a_number();
     }
     if((is_pos_inf(value_) && rhs.is_pos_inf(rhs.as_number())) ||
        (is_neg_inf(value_) && rhs.is_neg_inf(rhs.as_number())) )
     {
       return int_adapter::not_a_number();
     }
     if (is_infinity()) 
     {
       return *this;
     }
     if (rhs.is_pos_inf(rhs.as_number())) 
     {
       return int_adapter::neg_infinity();
     }
     if (rhs.is_neg_inf(rhs.as_number())) 
     {
       return int_adapter::pos_infinity();
     }
   }
   return int_adapter<int_type>(value_ - rhs.as_number());
 }
    void do_double_value(double value) override
    {
        begin_value();

        if (is_nan(value) && format_.replace_nan())
        {
            *os_ << format_.nan_replacement();
        }
        else if (is_pos_inf(value) && format_.replace_pos_inf())
        {
            *os_ << format_.pos_inf_replacement();
        }
        else if (is_neg_inf(value) && format_.replace_neg_inf())
        {
            *os_ << format_.neg_inf_replacement();
        }
        else if (format_.floatfield() != 0)
        {
            std::basic_ostringstream<Char> os;
            os.imbue(std::locale::classic());
            os.setf(format_.floatfield(), std::ios::floatfield);
            os << std::showpoint << std::setprecision(format_.precision()) << value;
            *os_ << os.str();
        }
        else
        {
            std::basic_string<Char> buf = float_to_string<Char>(value,format_.precision());
            *os_ << buf;
        }

        end_value();
    }
    void do_double_value(double value, uint8_t precision) override
    {
        begin_value();

        if (is_nan(value) && format_.replace_nan())
        {
            bos_.write(format_.nan_replacement());
        }
        else if (is_pos_inf(value) && format_.replace_pos_inf())
        {
            bos_.write(format_.pos_inf_replacement());
        }
        else if (is_neg_inf(value) && format_.replace_neg_inf())
        {
            bos_.write(format_.neg_inf_replacement());
        }
        //else if (format_.floatfield() != 0)
        //{
            //std::basic_ostringstream<CharT> os;
            //os.imbue(std::locale::classic());
            //os.setf(format_.floatfield(), std::ios::floatfield);
            //os << std::showpoint << std::setprecision(format_.precision()) << value;
            //*os_ << os.str();
        //}
        else
        {
            fp_.print(value,precision,bos_);
        }

        end_value();
    }
Exemple #6
0
std::string to_s(real_t n)
{
  if ( is_nan(n) ) return "+nan.0";
  if ( is_neg_inf(n) ) return "-inf.0";
  if ( is_pos_inf(n) ) return "+inf.0";

  char buf[64];
  sprintf(buf, "%g", n);
  return std::string(buf);
}