OpenMPCD
Scalar.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines helper functions for scalar types.
4  */
5 
6 #ifndef OPENMPCD_SCALAR_HPP
7 #define OPENMPCD_SCALAR_HPP
8 
10 
11 #include <boost/static_assert.hpp>
12 #include <boost/type_traits/is_floating_point.hpp>
13 #include <boost/utility/enable_if.hpp>
14 
15 #include <complex>
16 
17 namespace OpenMPCD
18 {
19 
20 /**
21  * Holds helper functions for scalar types.
22  */
23 namespace Scalar
24 {
25 ///@{
26 /**
27  * Returns the real part of the given value.
28  *
29  * @tparam T The type of the value to consider.
30  *
31  * @param[in] val The value to consider.
32  */
33 
34 template<typename T>
36 typename boost::enable_if<boost::is_floating_point<T>, T>::type
37  getRealPart(const T& val)
38 {
39  BOOST_STATIC_ASSERT(boost::is_floating_point<T>::value);
40 
41  return val;
42 }
43 
44 template<typename T>
46 typename boost::enable_if<boost::is_floating_point<T>, T>::type
47  getRealPart(const std::complex<T>& val)
48 {
49  BOOST_STATIC_ASSERT(boost::is_floating_point<T>::value);
50 
51  return val.real();
52 }
53 ///@}
54 
55 ///@{
56 /**
57  * Returns whether the given value is zero.
58  *
59  * @tparam T The type of the value to consider.
60  *
61  * @param[in] val The value to consider.
62  */
63 
64 template<typename T> OPENMPCD_CUDA_HOST_AND_DEVICE
65 typename boost::enable_if<boost::is_floating_point<T>, bool>::type
66  isZero(const T& val)
67 {
68  BOOST_STATIC_ASSERT(boost::is_floating_point<T>::value);
69 
70  return val == 0;
71 }
72 
73 template<typename T> OPENMPCD_CUDA_HOST_AND_DEVICE
74 typename boost::enable_if<boost::is_floating_point<T>, bool>::type
75  isZero(const std::complex<T>& val)
76 {
77  BOOST_STATIC_ASSERT(boost::is_floating_point<T>::value);
78 
79  return val == std::complex<T>(0, 0);
80 }
81 ///@}
82 
83 } //namespace Scalar
84 } //namespace OpenMPCD
85 
86 #endif
OpenMPCD::Scalar::isZero
OPENMPCD_CUDA_HOST_AND_DEVICE boost::enable_if< boost::is_floating_point< T >, bool >::type isZero(const T &val)
Returns whether the given value is zero.
Definition: Scalar.hpp:66
OPENMPCD_CUDA_HOST_AND_DEVICE
#define OPENMPCD_CUDA_HOST_AND_DEVICE
Denotes a function to be callable both from the Host and from a CUDA Device.
Definition: Macros.hpp:15
Macros.hpp
OpenMPCD::Scalar::getRealPart
OPENMPCD_CUDA_HOST_AND_DEVICE boost::enable_if< boost::is_floating_point< T >, T >::type getRealPart(const T &val)
Returns the real part of the given value.
Definition: Scalar.hpp:37