1 // (C) Copyright John Maddock 2005.
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)
6 #ifndef BOOST_MATH_EXPM1_INCLUDED
7 #define BOOST_MATH_EXPM1_INCLUDED
10 #include <math.h> // platform's ::expm1
11 #include <boost/limits.hpp>
12 #include <boost/math/special_functions/detail/series.hpp>
14 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
15 # include <boost/static_assert.hpp>
17 # include <boost/assert.hpp>
20 #ifdef BOOST_NO_STDC_NAMESPACE
21 namespace std{ using ::exp; using ::fabs; }
25 namespace boost{ namespace math{
29 // Functor expm1_series returns the next term in the Taylor series
31 // each time that operator() is invoked.
36 typedef T result_type;
39 : k(0), m_x(x), m_term(1) {}
58 expm1_series(const expm1_series&);
59 expm1_series& operator=(const expm1_series&);
65 // Algorithm expm1 is part of C99, but is not yet provided by many compilers.
67 // This version uses a Taylor series expansion for 0.5 > |x| > epsilon.
72 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
73 BOOST_STATIC_ASSERT(::std::numeric_limits<T>::is_specialized);
75 BOOST_ASSERT(std::numeric_limits<T>::is_specialized);
80 return std::exp(x) - T(1);
81 if(a < std::numeric_limits<T>::epsilon())
83 detail::expm1_series<T> s(x);
84 T result = detail::kahan_sum_series(s, std::numeric_limits<T>::digits + 2);
87 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
88 inline float expm1(float z)
90 return expm1<float>(z);
92 inline double expm1(double z)
94 return expm1<double>(z);
96 inline long double expm1(long double z)
98 return expm1<long double>(z);
103 # ifndef BOOST_HAS_expm1
104 # define BOOST_HAS_expm1
109 #ifdef BOOST_HAS_EXPM1
110 # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
111 inline float expm1(float x){ return ::expm1f(x); }
112 inline long double expm1(long double x){ return ::expm1l(x); }
114 inline float expm1(float x){ return ::expm1(x); }
116 inline double expm1(double x){ return ::expm1(x); }
121 #endif // BOOST_MATH_HYPOT_INCLUDED