Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:19

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file complex.hpp
0003 ///
0004 //  Copyright 2005 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
0009 #define BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
0010 
0011 #ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
0012 # error Include this file before boost/accumulators/numeric/functional.hpp
0013 #endif
0014 
0015 #include <complex>
0016 #include <boost/mpl/or.hpp>
0017 #include <boost/type_traits/is_same.hpp>
0018 #include <boost/utility/enable_if.hpp>
0019 #include <boost/typeof/std/complex.hpp>
0020 #include <boost/accumulators/numeric/functional_fwd.hpp>
0021 
0022 namespace boost { namespace numeric { namespace operators
0023 {
0024     // So that the stats compile when Sample type is std::complex
0025     template<typename T, typename U>
0026     typename
0027         disable_if<
0028             mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
0029           , std::complex<T>
0030         >::type
0031     operator *(std::complex<T> ri, U const &u)
0032     {
0033         // BUGBUG promote result to typeof(T()*u) ?
0034         return ri *= static_cast<T>(u);
0035     }
0036 
0037     template<typename T, typename U>
0038     typename
0039         disable_if<
0040             mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
0041           , std::complex<T>
0042         >::type
0043     operator /(std::complex<T> ri, U const &u)
0044     {
0045         // BUGBUG promote result to typeof(T()*u) ?
0046         return ri /= static_cast<T>(u);
0047     }
0048 
0049 }}} // namespace boost::numeric::operators
0050 
0051 namespace boost { namespace numeric
0052 {
0053     namespace detail
0054     {
0055         template<typename T>
0056         struct one_complex
0057         {
0058             static std::complex<T> const value;
0059         };
0060 
0061         template<typename T>
0062         std::complex<T> const one_complex<T>::value
0063           = std::complex<T>(numeric::one<T>::value, numeric::one<T>::value);
0064     }
0065 
0066     /// INTERNAL ONLY
0067     ///
0068     template<typename T>
0069     struct one<std::complex<T> >
0070       : detail::one_complex<T>
0071     {
0072         typedef one type;
0073         typedef std::complex<T> value_type;
0074         operator value_type const & () const
0075         {
0076             return detail::one_complex<T>::value;
0077         }
0078     };
0079 
0080 }} // namespace boost::numeric
0081 
0082 #endif