rounded_transc.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Boost interval/rounded_transc.hpp template implementation file
  2. *
  3. * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
  4. *
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * (See accompanying file LICENSE_1_0.txt or
  7. * copy at http://www.boost.org/LICENSE_1_0.txt)
  8. */
  9. #ifndef BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP
  10. #define BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP
  11. #include <boost/numeric/interval/rounding.hpp>
  12. #include <boost/numeric/interval/detail/bugs.hpp>
  13. #include <boost/config/no_tr1/cmath.hpp>
  14. namespace boost {
  15. namespace numeric {
  16. namespace interval_lib {
  17. template<class T, class Rounding>
  18. struct rounded_transc_exact: Rounding
  19. {
  20. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  21. T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); } \
  22. T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); }
  23. BOOST_NUMERIC_INTERVAL_new_func(exp)
  24. BOOST_NUMERIC_INTERVAL_new_func(log)
  25. BOOST_NUMERIC_INTERVAL_new_func(sin)
  26. BOOST_NUMERIC_INTERVAL_new_func(cos)
  27. BOOST_NUMERIC_INTERVAL_new_func(tan)
  28. BOOST_NUMERIC_INTERVAL_new_func(asin)
  29. BOOST_NUMERIC_INTERVAL_new_func(acos)
  30. BOOST_NUMERIC_INTERVAL_new_func(atan)
  31. BOOST_NUMERIC_INTERVAL_new_func(sinh)
  32. BOOST_NUMERIC_INTERVAL_new_func(cosh)
  33. BOOST_NUMERIC_INTERVAL_new_func(tanh)
  34. # undef BOOST_NUMERIC_INTERVAL_new_func
  35. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  36. T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); } \
  37. T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); }
  38. BOOST_NUMERIC_INTERVAL_new_func(asinh)
  39. BOOST_NUMERIC_INTERVAL_new_func(acosh)
  40. BOOST_NUMERIC_INTERVAL_new_func(atanh)
  41. # undef BOOST_NUMERIC_INTERVAL_new_func
  42. };
  43. template<class T, class Rounding>
  44. struct rounded_transc_std: Rounding
  45. {
  46. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  47. T f##_down(const T& x) \
  48. { BOOST_NUMERIC_INTERVAL_using_math(f); \
  49. this->downward(); return this->force_rounding(f(x)); } \
  50. T f##_up (const T& x) \
  51. { BOOST_NUMERIC_INTERVAL_using_math(f); \
  52. this->upward(); return this->force_rounding(f(x)); }
  53. BOOST_NUMERIC_INTERVAL_new_func(exp)
  54. BOOST_NUMERIC_INTERVAL_new_func(log)
  55. BOOST_NUMERIC_INTERVAL_new_func(sin)
  56. BOOST_NUMERIC_INTERVAL_new_func(cos)
  57. BOOST_NUMERIC_INTERVAL_new_func(tan)
  58. BOOST_NUMERIC_INTERVAL_new_func(asin)
  59. BOOST_NUMERIC_INTERVAL_new_func(acos)
  60. BOOST_NUMERIC_INTERVAL_new_func(atan)
  61. BOOST_NUMERIC_INTERVAL_new_func(sinh)
  62. BOOST_NUMERIC_INTERVAL_new_func(cosh)
  63. BOOST_NUMERIC_INTERVAL_new_func(tanh)
  64. # undef BOOST_NUMERIC_INTERVAL_new_func
  65. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  66. T f##_down(const T& x) \
  67. { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
  68. this->downward(); return this->force_rounding(f(x)); } \
  69. T f##_up (const T& x) \
  70. { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
  71. this->upward(); return this->force_rounding(f(x)); }
  72. BOOST_NUMERIC_INTERVAL_new_func(asinh)
  73. BOOST_NUMERIC_INTERVAL_new_func(acosh)
  74. BOOST_NUMERIC_INTERVAL_new_func(atanh)
  75. # undef BOOST_NUMERIC_INTERVAL_new_func
  76. };
  77. template<class T, class Rounding>
  78. struct rounded_transc_opp: Rounding
  79. {
  80. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  81. T f##_down(const T& x) \
  82. { BOOST_NUMERIC_INTERVAL_using_math(f); \
  83. this->downward(); T y = this->force_rounding(f(x)); \
  84. this->upward(); return y; } \
  85. T f##_up (const T& x) \
  86. { BOOST_NUMERIC_INTERVAL_using_math(f); \
  87. return this->force_rounding(f(x)); }
  88. BOOST_NUMERIC_INTERVAL_new_func(exp)
  89. BOOST_NUMERIC_INTERVAL_new_func(log)
  90. BOOST_NUMERIC_INTERVAL_new_func(cos)
  91. BOOST_NUMERIC_INTERVAL_new_func(acos)
  92. BOOST_NUMERIC_INTERVAL_new_func(cosh)
  93. # undef BOOST_NUMERIC_INTERVAL_new_func
  94. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  95. T f##_down(const T& x) \
  96. { BOOST_NUMERIC_INTERVAL_using_math(f); \
  97. return -this->force_rounding(-f(x)); } \
  98. T f##_up (const T& x) \
  99. { BOOST_NUMERIC_INTERVAL_using_math(f); \
  100. return this->force_rounding(f(x)); }
  101. BOOST_NUMERIC_INTERVAL_new_func(sin)
  102. BOOST_NUMERIC_INTERVAL_new_func(tan)
  103. BOOST_NUMERIC_INTERVAL_new_func(asin)
  104. BOOST_NUMERIC_INTERVAL_new_func(atan)
  105. BOOST_NUMERIC_INTERVAL_new_func(sinh)
  106. BOOST_NUMERIC_INTERVAL_new_func(tanh)
  107. # undef BOOST_NUMERIC_INTERVAL_new_func
  108. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  109. T f##_down(const T& x) \
  110. { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
  111. this->downward(); T y = this->force_rounding(f(x)); \
  112. this->upward(); return y; } \
  113. T f##_up (const T& x) \
  114. { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
  115. return this->force_rounding(f(x)); }
  116. BOOST_NUMERIC_INTERVAL_new_func(asinh)
  117. BOOST_NUMERIC_INTERVAL_new_func(atanh)
  118. # undef BOOST_NUMERIC_INTERVAL_new_func
  119. # define BOOST_NUMERIC_INTERVAL_new_func(f) \
  120. T f##_down(const T& x) \
  121. { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
  122. return -this->force_rounding(-f(x)); } \
  123. T f##_up (const T& x) \
  124. { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \
  125. return this->force_rounding(f(x)); }
  126. BOOST_NUMERIC_INTERVAL_new_func(acosh)
  127. # undef BOOST_NUMERIC_INTERVAL_new_func
  128. };
  129. } // namespace interval_lib
  130. } // namespace numeric
  131. } // namespace boost
  132. #endif // BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP