powers.qbk 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. [section:powers Basic Functions]
  2. [section:sin_pi sin_pi]
  3. ``
  4. #include <boost/math/special_functions/sin_pi.hpp>
  5. ``
  6. namespace boost{ namespace math{
  7. template <class T>
  8. ``__sf_result`` sin_pi(T x);
  9. template <class T, class ``__Policy``>
  10. ``__sf_result`` sin_pi(T x, const ``__Policy``&);
  11. }} // namespaces
  12. Returns the sine of ['[pi][thin]x]. [/thin space to avoid collision of italic chars.]
  13. The return type of this function is computed using the __arg_promotion_rules:
  14. the return is `double` when /x/ is an integer type and T otherwise.
  15. [optional_policy]
  16. This function performs exact all-integer arithmetic argument reduction before computing the sine of ['[pi][sdot]x].
  17. [table_sin_pi]
  18. [endsect] [/section:sin_pi sin_pi]
  19. [section:cos_pi cos_pi]
  20. ``
  21. #include <boost/math/special_functions/cos_pi.hpp>
  22. ``
  23. namespace boost{ namespace math{
  24. template <class T>
  25. ``__sf_result`` cos_pi(T x);
  26. template <class T, class ``__Policy``>
  27. ``__sf_result`` cos_pi(T x, const ``__Policy``&);
  28. }} // namespaces
  29. Returns the cosine of ['[pi][thin]x].
  30. The return type of this function is computed using the __arg_promotion_rules:
  31. the return is `double` when /x/ is an integer type and T otherwise.
  32. [optional_policy]
  33. This function performs exact all-integer arithmetic argument reduction before computing the cosine of ['[pi][cdot]x].
  34. [table_cos_pi]
  35. [endsect] [/section:cos_pi cos_pi]
  36. [section:log1p log1p]
  37. ``
  38. #include <boost/math/special_functions/log1p.hpp>
  39. ``
  40. namespace boost{ namespace math{
  41. template <class T>
  42. ``__sf_result`` log1p(T x);
  43. template <class T, class ``__Policy``>
  44. ``__sf_result`` log1p(T x, const ``__Policy``&);
  45. }} // namespaces
  46. Returns the natural logarithm of /x+1/.
  47. The return type of this function is computed using the __arg_promotion_rules:
  48. the return is `double` when /x/ is an integer type and T otherwise.
  49. [optional_policy]
  50. There are many situations where it is desirable to compute `log(x+1)`.
  51. However, for small /x/ then /x+1/ suffers from catastrophic cancellation errors
  52. so that /x+1 == 1/ and /log(x+1) == 0/, when in fact for very small x, the
  53. best approximation to /log(x+1)/ would be /x/. `log1p` calculates the best
  54. approximation to `log(1+x)` using a Taylor series expansion for accuracy
  55. (less than __te).
  56. Alternatively note that there are faster methods available,
  57. for example using the equivalence:
  58. [:['log(1+x) == (log(1+x) * x) / ((1+x) - 1)]]
  59. However, experience has shown that these methods tend to fail quite spectacularly
  60. once the compiler's optimizations are turned on, consequently they are
  61. used only when known not to break with a particular compiler.
  62. In contrast, the series expansion method seems to be reasonably
  63. immune to optimizer-induced errors.
  64. Finally when macro BOOST_HAS_LOG1P is defined then the `float/double/long double`
  65. specializations of this template simply forward to the platform's
  66. native (POSIX) implementation of this function.
  67. The following graph illustrates the behaviour of log1p:
  68. [graph log1p]
  69. [h4 Accuracy]
  70. For built in floating point types `log1p`
  71. should have approximately 1 __epsilon accuracy.
  72. [table_log1p]
  73. [h4 Testing]
  74. A mixture of spot test sanity checks, and random high precision test values
  75. calculated using NTL::RR at 1000-bit precision.
  76. [endsect] [/section:log1p log1p]
  77. [section:expm1 expm1]
  78. ``
  79. #include <boost/math/special_functions/expm1.hpp>
  80. ``
  81. namespace boost{ namespace math{
  82. template <class T>
  83. ``__sf_result`` expm1(T x);
  84. template <class T, class ``__Policy``>
  85. ``__sf_result`` expm1(T x, const ``__Policy``&);
  86. }} // namespaces
  87. Returns e[super x] - 1.
  88. The return type of this function is computed using the __arg_promotion_rules:
  89. the return is `double` when /x/ is an integer type and T otherwise.
  90. [optional_policy]
  91. For small /x/, then __ex is very close to 1, as a result calculating __exm1 results
  92. in catastrophic cancellation errors when /x/ is small. `expm1` calculates __exm1 using
  93. rational approximations (for up to 128-bit long doubles), otherwise via
  94. a series expansion when x is small (giving an accuracy of less than __te).
  95. Finally when BOOST_HAS_EXPM1 is defined then the `float/double/long double`
  96. specializations of this template simply forward to the platform's
  97. native (POSIX) implementation of this function.
  98. The following graph illustrates the behaviour of expm1:
  99. [graph expm1]
  100. [h4 Accuracy]
  101. For built in floating point types `expm1`
  102. should have approximately 1 epsilon accuracy.
  103. [table_expm1]
  104. [h4 Testing]
  105. A mixture of spot test sanity checks, and random high precision test values
  106. calculated using NTL::RR at 1000-bit precision.
  107. [endsect] [/section:expm1 expm1]
  108. [section:cbrt cbrt]
  109. ``
  110. #include <boost/math/special_functions/cbrt.hpp>
  111. ``
  112. namespace boost{ namespace math{
  113. template <class T>
  114. ``__sf_result`` cbrt(T x);
  115. template <class T, class ``__Policy``>
  116. ``__sf_result`` cbrt(T x, const ``__Policy``&);
  117. }} // namespaces
  118. Returns the cubed root of x: x[super 1/3] or [cbrt]x.
  119. The return type of this function is computed using the __arg_promotion_rules:
  120. the return is `double` when /x/ is an integer type and T otherwise.
  121. [optional_policy]
  122. Implemented using Halley iteration.
  123. The following graph illustrates the behaviour of cbrt:
  124. [graph cbrt]
  125. [h4 Accuracy]
  126. For built in floating-point types `cbrt` should have approximately 2 epsilon accuracy.
  127. [table_cbrt]
  128. [h4 Testing]
  129. A mixture of spot test sanity checks, and random high precision test values
  130. calculated using NTL::RR at 1000-bit precision.
  131. [endsect] [/section:cbrt cbrt]
  132. [section:sqrt1pm1 sqrt1pm1]
  133. ``
  134. #include <boost/math/special_functions/sqrt1pm1.hpp>
  135. ``
  136. namespace boost{ namespace math{
  137. template <class T>
  138. ``__sf_result`` sqrt1pm1(T x);
  139. template <class T, class ``__Policy``>
  140. ``__sf_result`` sqrt1pm1(T x, const ``__Policy``&);
  141. }} // namespaces
  142. Returns `sqrt(1+x) - 1`.
  143. The return type of this function is computed using the __arg_promotion_rules:
  144. the return is `double` when /x/ is an integer-type and T otherwise.
  145. [optional_policy]
  146. This function is useful when you need the difference between `sqrt(x)` and 1, when
  147. /x/ is itself close to 1.
  148. Implemented in terms of `log1p` and `expm1`.
  149. The following graph illustrates the behaviour of sqrt1pm1:
  150. [graph sqrt1pm1]
  151. [h4 Accuracy]
  152. For built in floating-point types `sqrt1pm1`
  153. should have approximately 3 epsilon accuracy.
  154. [table_sqrt1pm1]
  155. [h4 Testing]
  156. A selection of random high precision test values
  157. calculated using NTL::RR at 1000-bit precision.
  158. [endsect] [/section:sqrt1pm1 sqrt1pm1]
  159. [section:powm1 powm1]
  160. ``
  161. #include <boost/math/special_functions/powm1.hpp>
  162. ``
  163. namespace boost{ namespace math{
  164. template <class T1, class T2>
  165. ``__sf_result`` powm1(T1 x, T2 y);
  166. template <class T1, class T2, class ``__Policy``>
  167. ``__sf_result`` powm1(T1 x, T2 y, const ``__Policy``&);
  168. }} // namespaces
  169. Returns x[super y ] - 1.
  170. The return type of this function is computed using the __arg_promotion_rules
  171. when T1 and T2 are different types.
  172. [optional_policy]
  173. There are two domains where this is useful: when /y/ is very small, or when
  174. /x/ is close to 1.
  175. Implemented in terms of `expm1`.
  176. The following graph illustrates the behaviour of powm1:
  177. [graph powm1]
  178. [h4 Accuracy]
  179. Should have approximately 2-3 epsilon accuracy.
  180. [table_powm1]
  181. [h4 Testing]
  182. A selection of random high precision test values
  183. calculated using NTL::RR at 1000-bit precision.
  184. [endsect] [/section:powm1 powm1]
  185. [section:hypot hypot]
  186. template <class T1, class T2>
  187. ``__sf_result`` hypot(T1 x, T2 y);
  188. template <class T1, class T2, class ``__Policy``>
  189. ``__sf_result`` hypot(T1 x, T2 y, const ``__Policy``&);
  190. __effects computes [equation hypot]
  191. in such a way as to avoid undue underflow and overflow.
  192. The return type of this function is computed using the __arg_promotion_rules
  193. when T1 and T2 are of different types.
  194. [optional_policy]
  195. When calculating [equation hypot] it's quite easy for the intermediate terms to either
  196. overflow or underflow, even though the result is in fact perfectly representable.
  197. [h4 Implementation]
  198. The function is even and symmetric in /x/ and /y/, so first take assume
  199. ['x,y > 0] and ['x > y] (we can permute the arguments if this is not the case).
  200. Then if ['x * [epsilon] >= y] we can simply return /x/.
  201. Otherwise the result is given by:
  202. [equation hypot2]
  203. [endsect] [/section:hypot hypot]
  204. [include pow.qbk]
  205. [endsect] [/section:powers Logs, Powers, Roots and Exponentials]
  206. [/
  207. Copyright 2006 John Maddock and Paul A. Bristow.
  208. Distributed under the Boost Software License, Version 1.0.
  209. (See accompanying file LICENSE_1_0.txt or copy at
  210. http://www.boost.org/LICENSE_1_0.txt).
  211. ]