From f8082e18e752f798bbf61f95231be4a2bcf482ec Mon Sep 17 00:00:00 2001 From: "Paul A. Bristow" Date: Wed, 3 Jan 2007 17:40:22 +0000 Subject: [PATCH] a few tests for added constants using std functions. [SVN r3596] --- test/test_constants.cpp | 119 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 test/test_constants.cpp diff --git a/test/test_constants.cpp b/test/test_constants.cpp new file mode 100644 index 000000000..ad83508c5 --- /dev/null +++ b/test/test_constants.cpp @@ -0,0 +1,119 @@ +// Copyright Paul Bristow 2006. +// Copyright John Maddock 2006. + +// Use, modification and distribution are subject to 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) + +// test_uniform.cpp + +#define BOOST_MATH_THROW_ON_DOMAIN_ERROR +#define BOOST_MATH_THROW_ON_OVERFLOW_ERROR +//#define BOOST_MATH_THROW_ON_UNDERFLOW_ERROR +// Ignore underflow to zero. + +#ifdef _MSC_VER +# pragma warning(disable: 4127) // conditional expression is constant. +# pragma warning(disable: 4100) // unreferenced formal parameter. +# pragma warning(disable: 4512) // assignment operator could not be generated. +# pragma warning(disable: 4510) // default constructor could not be generated. +# pragma warning(disable: 4610) // can never be instantiated - user defined constructor required. +# pragma warning(disable: 4180) // qualifier applied to function type has no meaning; ignored. +# if !(defined _SCL_SECURE_NO_DEPRECATE) || (_SCL_SECURE_NO_DEPRECATE == 0) +# pragma warning(disable: 4996) // 'std::char_traits::copy' was declared deprecated. +# endif +#endif + +#include // for real_concept +#include // Boost.Test +#include + +#include +#include + +#include + using std::cout; + using std::endl; + using std::setprecision; +#include + using std::numeric_limits; + +template +void test_spots(RealType T) +{ + // Basic santity checks for constants. + + RealType tolerance = static_cast(2e-15); // double + cout << "Tolerance for type " << typeid(T).name() << " is " << tolerance << "." << endl; + + using namespace boost::math::constants; + using namespace std; // Help ADL of std exp, log... + using std::exp; + + BOOST_CHECK_CLOSE_FRACTION(static_cast(3.14159265358979323846264338327950288419716939937510), pi(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(sqrt(3.14159265358979323846264338327950288419716939937510)), root_pi(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(sqrt(3.14159265358979323846264338327950288419716939937510/2)), root_half_pi(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(sqrt(3.14159265358979323846264338327950288419716939937510 * 2)), root_two_pi(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(sqrt(log(4.))), root_ln_four(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(2.71828182845904523536028747135266249775724709369995), e(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(0.5), half(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(0.57721566490153286060651209008240243104259335), euler(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(sqrt(2.)), root_two(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(log(2.)), ln_two(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(log(log(2.))), ln_ln_two(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(1)/3, third(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(2)/3, twothirds(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(0.14159265358979323846264338327950288419716939937510), pi_minus_three(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(4. - 3.14159265358979323846264338327950288419716939937510), four_minus_pi(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(pow((4. - 3.14159265358979323846264338327950288419716939937510), 1.5)), pow23_four_minus_pi(), tolerance); + BOOST_CHECK_CLOSE_FRACTION(static_cast(exp(-0.5)), exp_minus_half(), tolerance); + +} // template void test_spots(RealType) + +int test_main(int, char* []) +{ + + // Basic sanity-check spot values. + + + + + // (Parameter value, arbitrarily zero, only communicates the floating point type). + test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 % + test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 % +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + test_spots(0.0L); // Test long double. +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0582)) + test_spots(boost::math::concepts::real_concept(0.)); // Test real concept. +#endif +#else + std::cout << "The long double tests have been disabled on this platform " + "either because the long double overloads of the usual math functions are " + "not available at all, or because they are too inaccurate for these tests " + "to pass." << std::cout; +#endif + + return 0; +} // int test_main(int, char* []) + +/* + +Output: + +test_constants.cpp +Linking... +Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_constants.exe" +Running 1 test case... +Tolerance for type float is 2e-015. +Tolerance for type double is 2e-015. +Tolerance for type long double is 2e-015. +Tolerance for type class boost::math::concepts::real_concept is 2e-015. +*** No errors detected + + + + +*/ + +