コード例 #1
0
ファイル: limits.cpp プロジェクト: Flameeyes/stdcxx
void print_limits (std::ostream &strm, const char *tname, T)
{
#define PRINT_MEMBER(type, member)                     \
    strm << "    static " << type << " " #member " = "            \
         << std::numeric_limits<T>::member << ";\n"

    strm << "struct std::numeric_limits<" << tname << "> {\n";

    PRINT_MEMBER ("const bool", is_specialized);

    PRINT_MEMBER (tname, min ());
    PRINT_MEMBER (tname, max ());

    PRINT_MEMBER ("const int", digits);
    PRINT_MEMBER ("const int", digits10);

    PRINT_MEMBER ("const bool", is_signed);
    PRINT_MEMBER ("const bool", is_integer);
    PRINT_MEMBER ("const bool", is_exact);
    PRINT_MEMBER ("const int", radix);

    PRINT_MEMBER (tname, epsilon ());
    PRINT_MEMBER ("int", round_error ());

    PRINT_MEMBER ("const int", min_exponent);
    PRINT_MEMBER ("const int", min_exponent10);
    PRINT_MEMBER ("const int", max_exponent);
    PRINT_MEMBER ("const int", max_exponent10);

    PRINT_MEMBER ("const bool", has_infinity);
    PRINT_MEMBER ("const bool", has_quiet_NaN);
    PRINT_MEMBER ("const bool", has_signaling_NaN);
    PRINT_MEMBER ("const std::float_denorm_style", has_denorm);

    PRINT_MEMBER ("const bool", has_denorm_loss);

    PRINT_MEMBER (tname, infinity ());
    PRINT_MEMBER (tname, quiet_NaN ());
    PRINT_MEMBER (tname, signaling_NaN ());
    PRINT_MEMBER (tname, denorm_min ());

    PRINT_MEMBER ("const bool", is_iec559);
    PRINT_MEMBER ("const bool", is_bounded);
    PRINT_MEMBER ("const bool", is_modulo);

    PRINT_MEMBER ("const bool", traps);
    PRINT_MEMBER ("const bool", tinyness_before);

    PRINT_MEMBER ("const int", round_style);

    strm << "};\n";
}
コード例 #2
0
ファイル: numinquire.cpp プロジェクト: AtomAleks/PyProp
int main()
{
    double z = 1.0;

    cout << "Some inquiries into the nature of double:" << endl
         << "digits(z) = " << digits(z) << endl
         << "epsilon(z) = " << epsilon(z) << endl
         << "huge(z) = " << huge(z) << endl
         << "tiny(z) = " << tiny(z) << endl
         << "max_exponent(z) = " << max_exponent(z) << endl
         << "min_exponent(z) = " << min_exponent(z) << endl
         << "max_exponent10(z) = " << max_exponent10(z) << endl
         << "min_exponent10(z) = " << min_exponent10(z) << endl
         << "precision(z) = " << precision(z) << endl
         << "radix(z) = " << radix(z) << endl;

    Range r = range(z);
    cout << "range(z) = [ " << r.first() << ", " << r.last() << " ]"
         << endl;

    cout << endl << "More obscure properties:" << endl
         << "is_signed(z) = " << is_signed(z) << endl
         << "is_integer(z) = " << is_integer(z) << endl
         << "is_exact(z) = " << is_exact(z) << endl
         << "round_error(z) = " << round_error(z) << endl
         << "has_infinity(z) = " << has_infinity(z) << endl
         << "has_quiet_NaN(z) = " << has_quiet_NaN(z) << endl
         << "has_signaling_NaN(z) = " << has_signaling_NaN(z) << endl
         << "has_denorm(z) = " << has_denorm(z) << endl
         << "has_denorm_loss(z) = " << has_denorm_loss(z) << endl
         << "infinity(z) = " << infinity(z) << endl
         << "quiet_NaN(z) = " << quiet_NaN(z) << endl
         << "signaling_NaN(z) = " << signaling_NaN(z) << endl
         << "denorm_min(z) = " << denorm_min(z) << endl
         << "is_iec559(z) = " << is_iec559(z) << endl
         << "is_bounded(z) = " << is_bounded(z) << endl
         << "is_modulo(z) = " << is_modulo(z) << endl
         << "traps(z) = " << traps(z) << endl
         << "tinyness_before(z) = " << tinyness_before(z) << endl;

    return 0;
}
コード例 #3
0
void test()
{
   //
   // Note really a test just yet, but we can at least print out all the values:
   //
   std::cout << "numeric_limits values for type " << typeid(Number).name() << std::endl;

   PRINT(is_specialized);
   if(std::numeric_limits<Number>::is_integer)
   {
      std::cout << std::hex << std::showbase;
   }
   std::cout << "max()" << " = " << (std::numeric_limits<Number>::max)() << std::endl;
   if(std::numeric_limits<Number>::is_integer)
   {
      std::cout << std::dec;
   }
   std::cout << "max()" << " = " << (std::numeric_limits<Number>::max)() << std::endl;
   std::cout << "min()" << " = " << (std::numeric_limits<Number>::min)() << std::endl;
#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
   PRINT(lowest());
#endif
   PRINT(digits);
   PRINT(digits10);
#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
   PRINT(max_digits10);
#endif
   PRINT(is_signed);
   PRINT(is_integer);
   PRINT(is_exact);
   PRINT(radix);
   PRINT(epsilon());
   PRINT(round_error());
   PRINT(min_exponent);
   PRINT(min_exponent10);
   PRINT(max_exponent);
   PRINT(max_exponent10);
   PRINT(has_infinity);
   PRINT(has_quiet_NaN);
   PRINT(has_signaling_NaN);
   PRINT(has_denorm);
   PRINT(has_denorm_loss);
   PRINT(infinity());
   PRINT(quiet_NaN());
   PRINT(signaling_NaN());
   PRINT(denorm_min());
   PRINT(is_iec559);
   PRINT(is_bounded);
   PRINT(is_modulo);
   PRINT(traps);
   PRINT(tinyness_before);
   PRINT(round_style);

   typedef typename boost::mpl::if_c<
      std::numeric_limits<Number>::is_specialized,
      typename boost::multiprecision::number_category<Number>::type,
      boost::mpl::int_<500> // not a number type
   >::type fp_test_type;

   test_specific<Number>(fp_test_type());
}