test_trig.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright John Maddock 2014.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <pch_light.hpp>
  6. #include "test_trig.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the functions sin_pi, cos_pi, with test data
  12. // generated at high precision naively using sin(pi*x) rather than
  13. // our routines.
  14. //
  15. void expected_results()
  16. {
  17. //
  18. // Define the max and mean errors expected for
  19. // various compilers and platforms.
  20. //
  21. const char* largest_type;
  22. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  23. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  24. {
  25. largest_type = "(long\\s+)?double|real_concept";
  26. }
  27. else
  28. {
  29. largest_type = "long double|real_concept";
  30. }
  31. #else
  32. largest_type = "(long\\s+)?double";
  33. #endif
  34. //
  35. // On MacOS X erfc has much higher error levels than
  36. // expected: given that the implementation is basically
  37. // just a rational function evaluation combined with
  38. // exponentiation, we conclude that exp and pow are less
  39. // accurate on this platform, especially when the result
  40. // is outside the range of a double.
  41. //
  42. add_expected_result(
  43. ".*", // compiler
  44. ".*", // stdlib
  45. ".*", // platform
  46. largest_type, // test type(s)
  47. ".*", // test data group
  48. ".*", 2, 1); // test function
  49. //
  50. // Finish off by printing out the compiler/stdlib/platform names,
  51. // we do this to make it easier to mark up expected error rates.
  52. //
  53. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  54. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  55. }
  56. BOOST_AUTO_TEST_CASE( test_main )
  57. {
  58. BOOST_MATH_CONTROL_FP;
  59. expected_results();
  60. test_trig(0.1F, "float");
  61. test_trig(0.1, "double");
  62. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  63. test_trig(0.1L, "long double");
  64. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  65. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  66. test_trig(boost::math::concepts::real_concept(0.1), "real_concept");
  67. #endif
  68. #endif
  69. #else
  70. std::cout << "<note>The long double tests have been disabled on this platform "
  71. "either because the long double overloads of the usual math functions are "
  72. "not available at all, or because they are too inaccurate for these tests "
  73. "to pass.</note>" << std::endl;
  74. #endif
  75. }