Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 /// \file complex.hpp
|
Chris@16
|
3 ///
|
Chris@16
|
4 // Copyright 2005 Eric Niebler. Distributed under the Boost
|
Chris@16
|
5 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
|
Chris@16
|
9 #define BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
|
Chris@16
|
10
|
Chris@16
|
11 #ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
|
Chris@16
|
12 # error Include this file before boost/accumulators/numeric/functional.hpp
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 #include <complex>
|
Chris@16
|
16 #include <boost/mpl/or.hpp>
|
Chris@16
|
17 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
18 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
19 #include <boost/typeof/std/complex.hpp>
|
Chris@16
|
20 #include <boost/accumulators/numeric/functional_fwd.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 namespace boost { namespace numeric { namespace operators
|
Chris@16
|
23 {
|
Chris@16
|
24 // So that the stats compile when Sample type is std::complex
|
Chris@16
|
25 template<typename T, typename U>
|
Chris@16
|
26 typename
|
Chris@16
|
27 disable_if<
|
Chris@16
|
28 mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
|
Chris@16
|
29 , std::complex<T>
|
Chris@16
|
30 >::type
|
Chris@16
|
31 operator *(std::complex<T> ri, U const &u)
|
Chris@16
|
32 {
|
Chris@16
|
33 // BUGBUG promote result to typeof(T()*u) ?
|
Chris@16
|
34 return ri *= static_cast<T>(u);
|
Chris@16
|
35 }
|
Chris@16
|
36
|
Chris@16
|
37 template<typename T, typename U>
|
Chris@16
|
38 typename
|
Chris@16
|
39 disable_if<
|
Chris@16
|
40 mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
|
Chris@16
|
41 , std::complex<T>
|
Chris@16
|
42 >::type
|
Chris@16
|
43 operator /(std::complex<T> ri, U const &u)
|
Chris@16
|
44 {
|
Chris@16
|
45 // BUGBUG promote result to typeof(T()*u) ?
|
Chris@16
|
46 return ri /= static_cast<T>(u);
|
Chris@16
|
47 }
|
Chris@16
|
48
|
Chris@16
|
49 }}} // namespace boost::numeric::operators
|
Chris@16
|
50
|
Chris@16
|
51 namespace boost { namespace numeric
|
Chris@16
|
52 {
|
Chris@16
|
53 namespace detail
|
Chris@16
|
54 {
|
Chris@16
|
55 template<typename T>
|
Chris@16
|
56 struct one_complex
|
Chris@16
|
57 {
|
Chris@16
|
58 static std::complex<T> const value;
|
Chris@16
|
59 };
|
Chris@16
|
60
|
Chris@16
|
61 template<typename T>
|
Chris@16
|
62 std::complex<T> const one_complex<T>::value
|
Chris@16
|
63 = std::complex<T>(numeric::one<T>::value, numeric::one<T>::value);
|
Chris@16
|
64 }
|
Chris@16
|
65
|
Chris@16
|
66 /// INTERNAL ONLY
|
Chris@16
|
67 ///
|
Chris@16
|
68 template<typename T>
|
Chris@16
|
69 struct one<std::complex<T> >
|
Chris@16
|
70 : detail::one_complex<T>
|
Chris@16
|
71 {
|
Chris@16
|
72 typedef one type;
|
Chris@16
|
73 typedef std::complex<T> value_type;
|
Chris@16
|
74 operator value_type const & () const
|
Chris@16
|
75 {
|
Chris@16
|
76 return detail::one_complex<T>::value;
|
Chris@16
|
77 }
|
Chris@16
|
78 };
|
Chris@16
|
79
|
Chris@16
|
80 }} // namespace boost::numeric
|
Chris@16
|
81
|
Chris@16
|
82 #endif
|