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][thin]x]. [/thin space to avoid collision of italic chars.]
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][sdot]x].
30 [endsect] [/section:sin_pi sin_pi]
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][thin]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][cdot]x].
59 [endsect] [/section:cos_pi cos_pi]
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.
83 There are many situations where it is desirable to compute `log(x+1)`.
84 However, for small /x/ then /x+1/ suffers from catastrophic cancellation errors
85 so that /x+1 == 1/ and /log(x+1) == 0/, when in fact for very small x, the
86 best approximation to /log(x+1)/ would be /x/. `log1p` calculates the best
87 approximation to `log(1+x)` using a Taylor series expansion for accuracy
89 Alternatively note that there are faster methods available,
90 for example using the equivalence:
92 [:['log(1+x) == (log(1+x) * x) / ((1+x) - 1)]]
94 However, experience has shown that these methods tend to fail quite spectacularly
95 once the compiler's optimizations are turned on, consequently they are
96 used only when known not to break with a particular compiler.
97 In contrast, the series expansion method seems to be reasonably
98 immune to optimizer-induced errors.
100 Finally when macro BOOST_HAS_LOG1P is defined then the `float/double/long double`
101 specializations of this template simply forward to the platform's
102 native (POSIX) implementation of this function.
104 The following graph illustrates the behaviour of log1p:
110 For built in floating point types `log1p`
111 should have approximately 1 __epsilon accuracy.
117 A mixture of spot test sanity checks, and random high precision test values
118 calculated using NTL::RR at 1000-bit precision.
120 [endsect] [/section:log1p log1p]
122 [section:expm1 expm1]
125 #include <boost/math/special_functions/expm1.hpp>
128 namespace boost{ namespace math{
131 ``__sf_result`` expm1(T x);
133 template <class T, class ``__Policy``>
134 ``__sf_result`` expm1(T x, const ``__Policy``&);
138 Returns e[super x] - 1.
140 The return type of this function is computed using the __arg_promotion_rules:
141 the return is `double` when /x/ is an integer type and T otherwise.
145 For small /x/, then __ex is very close to 1, as a result calculating __exm1 results
146 in catastrophic cancellation errors when /x/ is small. `expm1` calculates __exm1 using
147 rational approximations (for up to 128-bit long doubles), otherwise via
148 a series expansion when x is small (giving an accuracy of less than __te).
150 Finally when BOOST_HAS_EXPM1 is defined then the `float/double/long double`
151 specializations of this template simply forward to the platform's
152 native (POSIX) implementation of this function.
154 The following graph illustrates the behaviour of expm1:
160 For built in floating point types `expm1`
161 should have approximately 1 epsilon accuracy.
167 A mixture of spot test sanity checks, and random high precision test values
168 calculated using NTL::RR at 1000-bit precision.
170 [endsect] [/section:expm1 expm1]
175 #include <boost/math/special_functions/cbrt.hpp>
178 namespace boost{ namespace math{
181 ``__sf_result`` cbrt(T x);
183 template <class T, class ``__Policy``>
184 ``__sf_result`` cbrt(T x, const ``__Policy``&);
188 Returns the cubed root of x: x[super 1/3] or [cbrt]x.
190 The return type of this function is computed using the __arg_promotion_rules:
191 the return is `double` when /x/ is an integer type and T otherwise.
195 Implemented using Halley iteration.
197 The following graph illustrates the behaviour of cbrt:
203 For built in floating-point types `cbrt` should have approximately 2 epsilon accuracy.
209 A mixture of spot test sanity checks, and random high precision test values
210 calculated using NTL::RR at 1000-bit precision.
212 [endsect] [/section:cbrt cbrt]
214 [section:sqrt1pm1 sqrt1pm1]
217 #include <boost/math/special_functions/sqrt1pm1.hpp>
219 namespace boost{ namespace math{
222 ``__sf_result`` sqrt1pm1(T x);
224 template <class T, class ``__Policy``>
225 ``__sf_result`` sqrt1pm1(T x, const ``__Policy``&);
229 Returns `sqrt(1+x) - 1`.
231 The return type of this function is computed using the __arg_promotion_rules:
232 the return is `double` when /x/ is an integer-type and T otherwise.
236 This function is useful when you need the difference between `sqrt(x)` and 1, when
237 /x/ is itself close to 1.
239 Implemented in terms of `log1p` and `expm1`.
241 The following graph illustrates the behaviour of sqrt1pm1:
247 For built in floating-point types `sqrt1pm1`
248 should have approximately 3 epsilon accuracy.
254 A selection of random high precision test values
255 calculated using NTL::RR at 1000-bit precision.
257 [endsect] [/section:sqrt1pm1 sqrt1pm1]
259 [section:powm1 powm1]
262 #include <boost/math/special_functions/powm1.hpp>
264 namespace boost{ namespace math{
266 template <class T1, class T2>
267 ``__sf_result`` powm1(T1 x, T2 y);
269 template <class T1, class T2, class ``__Policy``>
270 ``__sf_result`` powm1(T1 x, T2 y, const ``__Policy``&);
274 Returns x[super y ] - 1.
276 The return type of this function is computed using the __arg_promotion_rules
277 when T1 and T2 are different types.
281 There are two domains where this is useful: when /y/ is very small, or when
284 Implemented in terms of `expm1`.
286 The following graph illustrates the behaviour of powm1:
292 Should have approximately 2-3 epsilon accuracy.
298 A selection of random high precision test values
299 calculated using NTL::RR at 1000-bit precision.
301 [endsect] [/section:powm1 powm1]
303 [section:hypot hypot]
305 template <class T1, class T2>
306 ``__sf_result`` hypot(T1 x, T2 y);
308 template <class T1, class T2, class ``__Policy``>
309 ``__sf_result`` hypot(T1 x, T2 y, const ``__Policy``&);
311 __effects computes [equation hypot]
312 in such a way as to avoid undue underflow and overflow.
314 The return type of this function is computed using the __arg_promotion_rules
315 when T1 and T2 are of different types.
319 When calculating [equation hypot] it's quite easy for the intermediate terms to either
320 overflow or underflow, even though the result is in fact perfectly representable.
324 The function is even and symmetric in /x/ and /y/, so first take assume
325 ['x,y > 0] and ['x > y] (we can permute the arguments if this is not the case).
327 Then if ['x * [epsilon] >= y] we can simply return /x/.
329 Otherwise the result is given by:
333 [endsect] [/section:hypot hypot]
337 [endsect] [/section:powers Logs, Powers, Roots and Exponentials]
340 Copyright 2006 John Maddock and Paul A. Bristow.
341 Distributed under the Boost Software License, Version 1.0.
342 (See accompanying file LICENSE_1_0.txt or copy at
343 http://www.boost.org/LICENSE_1_0.txt).