1 /*==============================================================================
2     Copyright (c) 2011 Steven Watanabe
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 
8 #ifndef BOOST_PHOENIX_CMATH_HPP_INCLUDED
9 #define BOOST_PHOENIX_CMATH_HPP_INCLUDED
10 
11 #include <boost/phoenix/core/limits.hpp>
12 #include <cmath>
13 #include <boost/phoenix/function/adapt_callable.hpp>
14 #include <boost/type_traits/declval.hpp>
15 #include <boost/phoenix/support/iterate.hpp>
16 
17 namespace boost {
18 
19 #if (defined (BOOST_NO_CXX11_DECLTYPE) || \
20      defined (BOOST_INTEL_CXX_VERSION) || \
21              (BOOST_GCC_VERSION < 40500) )
22 #define BOOST_PHOENIX_MATH_FUNCTION_RESULT_TYPE(name, n)                \
23     typename proto::detail::uncvref<A0>::type
24 #else
25 #define BOOST_PHOENIX_MATH_FUNCTION_RESULT_TYPE(name, n)                \
26     decltype(name(BOOST_PP_ENUM_BINARY_PARAMS(                          \
27                       n                                                 \
28                     , boost::declval<typename proto::detail::uncvref<A  \
29                     ,  >::type>() BOOST_PP_INTERCEPT)))
30 #endif
31 #define BOOST_PHOENIX_MATH_FUNCTION(name, n)                            \
32     namespace phoenix_impl {                                            \
33     struct name ## _impl {                                              \
34         template<class Sig>                                             \
35         struct result;                                                  \
36         template<class This, BOOST_PHOENIX_typename_A(n)>               \
37         struct result<This(BOOST_PHOENIX_A(n))>                         \
38         {                                                               \
39             typedef                                                     \
40                 BOOST_PHOENIX_MATH_FUNCTION_RESULT_TYPE(name, n)        \
41                 type;                                                   \
42         };                                                              \
43         template<BOOST_PHOENIX_typename_A(n)>                           \
44         typename result<name ## _impl(BOOST_PHOENIX_A(n))>::type        \
45         operator()(BOOST_PHOENIX_A_const_ref_a(n)) const {              \
46             using namespace std;                                        \
47             return name(BOOST_PHOENIX_a(n));                            \
48         }                                                               \
49     };                                                                  \
50     }                                                                   \
51     namespace phoenix {                                                 \
52     BOOST_PHOENIX_ADAPT_CALLABLE(name, phoenix_impl::name ## _impl, n)  \
53     }
54 
55 BOOST_PHOENIX_MATH_FUNCTION(acos, 1)
56 BOOST_PHOENIX_MATH_FUNCTION(asin, 1)
57 BOOST_PHOENIX_MATH_FUNCTION(atan, 1)
58 BOOST_PHOENIX_MATH_FUNCTION(atan2, 2)
59 BOOST_PHOENIX_MATH_FUNCTION(ceil, 1)
60 BOOST_PHOENIX_MATH_FUNCTION(cos, 1)
61 BOOST_PHOENIX_MATH_FUNCTION(cosh, 1)
62 BOOST_PHOENIX_MATH_FUNCTION(exp, 1)
63 BOOST_PHOENIX_MATH_FUNCTION(fabs, 1)
64 BOOST_PHOENIX_MATH_FUNCTION(floor, 1)
65 BOOST_PHOENIX_MATH_FUNCTION(fmod, 2)
66 BOOST_PHOENIX_MATH_FUNCTION(frexp, 2)
67 BOOST_PHOENIX_MATH_FUNCTION(ldexp, 2)
68 BOOST_PHOENIX_MATH_FUNCTION(log, 1)
69 BOOST_PHOENIX_MATH_FUNCTION(log10, 1)
70 BOOST_PHOENIX_MATH_FUNCTION(modf, 2)
71 BOOST_PHOENIX_MATH_FUNCTION(pow, 2)
72 BOOST_PHOENIX_MATH_FUNCTION(sin, 1)
73 BOOST_PHOENIX_MATH_FUNCTION(sinh, 1)
74 BOOST_PHOENIX_MATH_FUNCTION(sqrt, 1)
75 BOOST_PHOENIX_MATH_FUNCTION(tan, 1)
76 BOOST_PHOENIX_MATH_FUNCTION(tanh, 1)
77 
78 #undef BOOST_PHOENIX_MATH_FUNCTION
79 
80 }
81 
82 #endif
83