1 [section:powers Basic Functions]
3 [section:sin_pi sin_pi]
6 #include <boost/math/special_functions/sin_pi.hpp>
9 namespace boost{ namespace math{
12 ``__sf_result`` sin_pi(T x);
14 template <class T, class ``__Policy``>
15 ``__sf_result`` sin_pi(T x, const ``__Policy``&);
19 Returns the sine of ['[pi]x].
21 The return type of this function is computed using the __arg_promotion_rules:
22 the return is `double` when /x/ is an integer type and T otherwise.
26 This function performs exact all-integer arithmetic argument reduction before computing the sine of ['[pi]x].
32 [section:cos_pi cos_pi]
35 #include <boost/math/special_functions/cos_pi.hpp>
38 namespace boost{ namespace math{
41 ``__sf_result`` cos_pi(T x);
43 template <class T, class ``__Policy``>
44 ``__sf_result`` cos_pi(T x, const ``__Policy``&);
48 Returns the cosine of ['[pi]x].
50 The return type of this function is computed using the __arg_promotion_rules:
51 the return is `double` when /x/ is an integer type and T otherwise.
55 This function performs exact all-integer arithmetic argument reduction before computing the cosine of ['[pi]x].
64 #include <boost/math/special_functions/log1p.hpp>
67 namespace boost{ namespace math{
70 ``__sf_result`` log1p(T x);
72 template <class T, class ``__Policy``>
73 ``__sf_result`` log1p(T x, const ``__Policy``&);
77 Returns the natural logarithm of `x+1`.
79 The return type of this function is computed using the __arg_promotion_rules:
80 the return is `double` when /x/ is an integer type and T otherwise.
84 There are many situations where it is desirable to compute `log(x+1)`.
85 However, for small `x` then `x+1` suffers from catastrophic cancellation errors
86 so that `x+1 == 1` and `log(x+1) == 0`, when in fact for very small x, the
87 best approximation to `log(x+1)` would be `x`. `log1p` calculates the best
88 approximation to `log(1+x)` using a Taylor series expansion for accuracy
90 Alternatively note that there are faster methods available,
91 for example using the equivalence:
93 log(1+x) == (log(1+x) * x) / ((1+x) - 1)
95 However, experience has shown that these methods tend to fail quite spectacularly
96 once the compiler's optimizations are turned on, consequently they are
97 used only when known not to break with a particular compiler.
98 In contrast, the series expansion method seems to be reasonably
99 immune to optimizer-induced errors.
101 Finally when BOOST_HAS_LOG1P is defined then the `float/double/long double`
102 specializations of this template simply forward to the platform's
103 native (POSIX) implementation of this function.
105 The following graph illustrates the behaviour of log1p:
111 For built in floating point types `log1p`
112 should have approximately 1 epsilon accuracy.
118 A mixture of spot test sanity checks, and random high precision test values
119 calculated using NTL::RR at 1000-bit precision.
123 [section:expm1 expm1]
126 #include <boost/math/special_functions/expm1.hpp>
129 namespace boost{ namespace math{
132 ``__sf_result`` expm1(T x);
134 template <class T, class ``__Policy``>
135 ``__sf_result`` expm1(T x, const ``__Policy``&);
139 Returns e[super x] - 1.
141 The return type of this function is computed using the __arg_promotion_rules:
142 the return is `double` when /x/ is an integer type and T otherwise.
146 For small x, then __ex is very close to 1, as a result calculating __exm1 results
147 in catastrophic cancellation errors when x is small. `expm1` calculates __exm1 using
148 rational approximations (for up to 128-bit long doubles), otherwise via
149 a series expansion when x is small (giving an accuracy of less than __te).
151 Finally when BOOST_HAS_EXPM1 is defined then the `float/double/long double`
152 specializations of this template simply forward to the platform's
153 native (POSIX) implementation of this function.
155 The following graph illustrates the behaviour of expm1:
161 For built in floating point types `expm1`
162 should have approximately 1 epsilon accuracy.
168 A mixture of spot test sanity checks, and random high precision test values
169 calculated using NTL::RR at 1000-bit precision.
176 #include <boost/math/special_functions/cbrt.hpp>
179 namespace boost{ namespace math{
182 ``__sf_result`` cbrt(T x);
184 template <class T, class ``__Policy``>
185 ``__sf_result`` cbrt(T x, const ``__Policy``&);
189 Returns the cubed root of x: x[super 1/3].
191 The return type of this function is computed using the __arg_promotion_rules:
192 the return is `double` when /x/ is an integer type and T otherwise.
196 Implemented using Halley iteration.
198 The following graph illustrates the behaviour of cbrt:
204 For built in floating-point types `cbrt`
205 should have approximately 2 epsilon accuracy.
211 A mixture of spot test sanity checks, and random high precision test values
212 calculated using NTL::RR at 1000-bit precision.
216 [section:sqrt1pm1 sqrt1pm1]
219 #include <boost/math/special_functions/sqrt1pm1.hpp>
222 namespace boost{ namespace math{
225 ``__sf_result`` sqrt1pm1(T x);
227 template <class T, class ``__Policy``>
228 ``__sf_result`` sqrt1pm1(T x, const ``__Policy``&);
232 Returns `sqrt(1+x) - 1`.
234 The return type of this function is computed using the __arg_promotion_rules:
235 the return is `double` when /x/ is an integer type and T otherwise.
239 This function is useful when you need the difference between sqrt(x) and 1, when
240 x is itself close to 1.
242 Implemented in terms of `log1p` and `expm1`.
244 The following graph illustrates the behaviour of sqrt1pm1:
250 For built in floating-point types `sqrt1pm1`
251 should have approximately 3 epsilon accuracy.
257 A selection of random high precision test values
258 calculated using NTL::RR at 1000-bit precision.
262 [section:powm1 powm1]
265 #include <boost/math/special_functions/powm1.hpp>
268 namespace boost{ namespace math{
270 template <class T1, class T2>
271 ``__sf_result`` powm1(T1 x, T2 y);
273 template <class T1, class T2, class ``__Policy``>
274 ``__sf_result`` powm1(T1 x, T2 y, const ``__Policy``&);
278 Returns x[super y ] - 1.
280 The return type of this function is computed using the __arg_promotion_rules
281 when T1 and T2 are dufferent types.
285 There are two domains where this is useful: when y is very small, or when
288 Implemented in terms of `expm1`.
290 The following graph illustrates the behaviour of powm1:
296 Should have approximately 2-3 epsilon accuracy.
302 A selection of random high precision test values
303 calculated using NTL::RR at 1000-bit precision.
307 [section:hypot hypot]
309 template <class T1, class T2>
310 ``__sf_result`` hypot(T1 x, T2 y);
312 template <class T1, class T2, class ``__Policy``>
313 ``__sf_result`` hypot(T1 x, T2 y, const ``__Policy``&);
315 __effects computes [equation hypot]
316 in such a way as to avoid undue underflow and overflow.
318 The return type of this function is computed using the __arg_promotion_rules
319 when T1 and T2 are of different types.
323 When calculating [equation hypot] it's quite easy for the intermediate terms to either
324 overflow or underflow, even though the result is in fact perfectly representable.
328 The function is even and symmetric in x and y, so first take assume
329 ['x,y > 0] and ['x > y] (we can permute the arguments if this is not the case).
331 Then if ['x * [epsilon][space] >= y] we can simply return /x/.
333 Otherwise the result is given by:
342 [endsect][/section:powers Logs, Powers, Roots and Exponentials]
345 Copyright 2006 John Maddock and Paul A. Bristow.
346 Distributed under the Boost Software License, Version 1.0.
347 (See accompanying file LICENSE_1_0.txt or copy at
348 http://www.boost.org/LICENSE_1_0.txt).