test_cbrt.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright John Maddock 2006.
  2. // Copyright Paul A. Bristow 2010
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifdef _MSC_VER
  7. # pragma warning (disable : 4224)
  8. #endif
  9. #include <pch_light.hpp> // include /libs/math/src/
  10. #include "test_cbrt.hpp"
  11. #include <boost/math/special_functions/cbrt.hpp> // Added to avoid link failure missing cbrt variants.
  12. // Assumes special functions library built rather than included?
  13. //
  14. // DESCRIPTION:
  15. // ~~~~~~~~~~~~
  16. //
  17. // This file tests the function cbrt. The accuracy tests
  18. // use values generated with NTL::RR at 1000-bit precision
  19. // and our generic versions of these functions.
  20. //
  21. // Note that when this file is first run on a new platform many of
  22. // these tests will fail: the default accuracy is 1 epsilon which
  23. // is too tight for most platforms. In this situation you will
  24. // need to cast a human eye over the error rates reported and make
  25. // a judgement as to whether they are acceptable. Either way please
  26. // report the results to the Boost mailing list. Acceptable rates of
  27. // error are marked up below as a series of regular expressions that
  28. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  29. // along with the maximum expected peek and RMS mean errors for that
  30. // test.
  31. //
  32. void expected_results()
  33. {
  34. //
  35. // Define the max and mean errors expected for
  36. // various compilers and platforms.
  37. //
  38. const char* largest_type;
  39. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  40. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  41. {
  42. largest_type = "(long\\s+)?double|real_concept";
  43. }
  44. else
  45. {
  46. largest_type = "long double|real_concept";
  47. }
  48. #else
  49. largest_type = "(long\\s+)?double|real_concept";
  50. #endif
  51. add_expected_result(
  52. "Borland.*", // compiler
  53. ".*", // stdlib
  54. ".*", // platform
  55. "long double", // test type(s)
  56. ".*", // test data group
  57. ".*", 10, 6); // test function
  58. add_expected_result(
  59. ".*", // compiler
  60. ".*", // stdlib
  61. ".*", // platform
  62. largest_type, // test type(s)
  63. ".*", // test data group
  64. ".*", 2, 2); // test function
  65. //
  66. // Finish off by printing out the compiler/stdlib/platform names,
  67. // we do this to make it easier to mark up expected error rates.
  68. //
  69. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  70. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  71. }
  72. BOOST_AUTO_TEST_CASE( test_main )
  73. {
  74. expected_results();
  75. BOOST_MATH_CONTROL_FP;
  76. test_cbrt(0.1F, "float");
  77. test_cbrt(0.1, "double");
  78. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  79. test_cbrt(0.1L, "long double");
  80. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  81. test_cbrt(boost::math::concepts::real_concept(0.1), "real_concept");
  82. #endif
  83. #endif
  84. }