diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 new file mode 100644 index 00000000..fd323a48 --- /dev/null +++ b/example/Jamfile.v2 @@ -0,0 +1,95 @@ +# \libs\math\example\jamfile.v2 +# Runs multiprecision examples. +# Copyright 2014 John Maddock +# Copyright Paul A. Bristow 2014. +# Copyright Christpher Kormanyos 2014 + +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +# bring in the rules for testing +import testing ; +import modules ; +import path ; + +local ntl-path = [ modules.peek : NTL_PATH ] ; +local gmp_path = [ modules.peek : GMP_PATH ] ; +local mpfr_path = [ modules.peek : MPFR_PATH ] ; +local mpfi_path = [ modules.peek : MPFI_PATH ] ; +local tommath_path = [ modules.peek : TOMMATH_PATH ] ; + +project + : requirements + $(gmp_path) + $(gmp_path)/mpfr + $(gmp_path)/gmpfrxx + $(mpfr_path) + $(mpfi_path) + $(mpfi_path)/src + $(tommath_path) + ../include + ../../.. + gcc:-Wno-missing-braces + darwin:-Wno-missing-braces + acc:+W2068,2461,2236,4070 + intel:-Qwd264,239 + msvc:static + msvc:static + msvc:all + msvc:on + msvc:_CRT_SECURE_NO_DEPRECATE + msvc:_SCL_SECURE_NO_DEPRECATE + msvc:_SCL_SECURE_NO_WARNINGS + msvc:_CRT_SECURE_NO_WARNINGS + msvc:/wd4996 + msvc:/wd4512 + msvc:/wd4610 + msvc:/wd4510 + msvc:/wd4127 + msvc:/wd4701 + msvc:/wd4127 + msvc:/wd4305 + ; + +lib gmp : : $(gmp_path) ; +lib mpfr : : $(gmp_path) $(mpfr_path) $(mpfr_path)/build.vc10/lib/Win32/Debug ; +lib mpfi : : $(gmp_path) $(mpfr_path) $(mpfr_path)/build.vc10/lib/Win32/Debug $(mpfi_path) $(mpfi_path)/src ; +lib quadmath ; + +if $(tommath_path) +{ + lib tommath : [ GLOB $(tommath_path) : *.c ] ; + TOMMATH = tommath ; +} +else +{ + lib tommath : : $(tommath_path) ; + TOMMATH = tommath ; +} + +run cpp_int_snips.cpp ; + +run cpp_dec_float_snips.cpp ; + +run cpp_bin_float_snips.cpp ; + +run debug_adaptor_snips.cpp ; +run float128_snips.cpp quadmath : : : [ check-target-builds ../config//has_float128 : : no ] ; +run floating_point_examples.cpp ; +run gauss_laguerre_quadrature.cpp ; +run hypergeometric_luke_algorithms.cpp ; +run integer_examples.cpp ; +run logged_adaptor.cpp mpfi mpfr gmp : : : [ check-target-builds ../config//has_mpfi : : no ] ; +run mixed_integer_arithmetic.cpp ; +run numeric_limits_snips.cpp /boost//test_exec_monitor ; +run random_snips.cpp gmp : : : [ check-target-builds ../config//has_gmp : : no ] ; +run safe_prime.cpp ; + +run gmp_snips.cpp gmp : : : [ check-target-builds ../config//has_gmp : : no ] ; +run mpfi_snips.cpp mpfi mpfr gmp : : : [ check-target-builds ../config//has_mpfi : : no ] ; +run mpfr_snips.cpp mpfr gmp : : : [ check-target-builds ../config//has_mpfr : : no ] ; +run tommath_snips.cpp $(TOMMATH) : : : [ check-target-builds ../config//has_tommath : : no ] ; + + + + diff --git a/example/debug_adaptor_snips.cpp b/example/debug_adaptor_snips.cpp index 8de85dcf..ca19f444 100644 --- a/example/debug_adaptor_snips.cpp +++ b/example/debug_adaptor_snips.cpp @@ -3,7 +3,7 @@ // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_ -#include +#include #include #include diff --git a/example/numeric_limits_snips.cpp b/example/numeric_limits_snips.cpp index 02bd6da2..580a4e6b 100644 --- a/example/numeric_limits_snips.cpp +++ b/example/numeric_limits_snips.cpp @@ -44,7 +44,7 @@ bool nearly_equal(RealType a, RealType b) && (a + tolerance * std::abs(a) >= b - tolerance * std::abs(b)); } -int main() +int test_main(int argc, char**const argv) { try { @@ -308,15 +308,7 @@ with Boost.Test's macro `BOOST_CHECK_CLOSE_FRACTION` T expected = 1.0; T calculated = 1.0 + std::numeric_limits::epsilon(); - using boost::test_tools::check_is_close; - - bool r = check_is_close(expected, calculated, tolerance); - std::cout << std::boolalpha << r << std::endl; // true - -/*`If using Boost.Test, then call the macro version: -``BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance);`` -*/ - + BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance); //] [/tolerance_1] } @@ -336,10 +328,8 @@ so the default expression template parameter has been replaced by `et_off`.] cpp_dec_float_50 tolerance = 3 * std::numeric_limits::epsilon(); cpp_dec_float_50 expected = boost::math::constants::two_pi(); cpp_dec_float_50 calculated = 2 * boost::math::constants::pi(); - using boost::test_tools::check_is_close; - bool r = check_is_close(expected, calculated, tolerance); - std::cout << std::boolalpha << r << std::endl; // true + BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance); //] [/tolerance_2] } @@ -352,10 +342,8 @@ so the default expression template parameter has been replaced by `et_off`.] cpp_bin_float_quad tolerance = 3 * std::numeric_limits::epsilon(); cpp_bin_float_quad expected = boost::math::constants::two_pi(); cpp_bin_float_quad calculated = 2 * boost::math::constants::pi(); - using boost::test_tools::check_is_close; - bool r = check_is_close(expected, calculated, tolerance); - std::cout << std::boolalpha << r << std::endl; // true + BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance); //] [/tolerance_3] } @@ -376,13 +364,11 @@ so the default expression template parameter has been replaced by `et_off`.] cpp_bin_float_quad expected = NaN; cpp_bin_float_quad calculated = 2 * NaN; - using boost::test_tools::check_is_close; - - bool r = check_is_close(expected, expected, tolerance); - std::cout << std::boolalpha << r << std::endl; // false, as expected because all comparisons with NaNs are false. - - r = check_is_close(expected, calculated, tolerance); - std::cout << std::boolalpha << r << std::endl; // false, as expected because all comparisons with NaNs are false. + // Comparisons of NaN's always fail: + bool b = expected == calculated; + std::cout << b << std::endl; + BOOST_CHECK_NE(expected, expected); + BOOST_CHECK_NE(expected, calculated); } else { @@ -444,7 +430,6 @@ Similarly we can do the same with NaN (except that we cannot use `assert`) assert(ss.str() == "nan"); std::cout << "NaN output was " << ss.str() << std::endl; ss >> n; // Read back in. - assert(NaN == n); // Confirms that the floating-point values really are identical. std::cout << "NaN input was " << n << std::endl; } /*` @@ -455,4 +440,6 @@ Similarly we can do the same with NaN (except that we cannot use `assert`) //] [/facet_1] } + return 0; + } // int main() diff --git a/include/boost/multiprecision/cpp_bin_float.hpp b/include/boost/multiprecision/cpp_bin_float.hpp index 445271dc..170de2b4 100644 --- a/include/boost/multiprecision/cpp_bin_float.hpp +++ b/include/boost/multiprecision/cpp_bin_float.hpp @@ -315,7 +315,9 @@ public: if(m_sign != o.m_sign) return m_sign ? -1 : 1; int result; - if(m_exponent != o.m_exponent) + if(m_exponent == exponent_nan) + return -1; + else if(m_exponent != o.m_exponent) { if(m_exponent == exponent_zero) result = -1; diff --git a/include/boost/multiprecision/cpp_int.hpp b/include/boost/multiprecision/cpp_int.hpp index 651dabd6..789965ff 100644 --- a/include/boost/multiprecision/cpp_int.hpp +++ b/include/boost/multiprecision/cpp_int.hpp @@ -1258,7 +1258,7 @@ private: void do_assign_string(const char* s, const mpl::true_&) { std::size_t n = s ? std::strlen(s) : 0; - *this->limbs() = 0; + *this = 0; unsigned radix = 10; bool isneg = false; if(n && (*s == '-'))