OpenMPCD
ImplementationDetails/MathematicalFunctions.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Implements common mathematical functions.
4  */
5 
6 #ifndef OPENMPCD_UTILITY_IMPLEMENTATIONDETAILS_MATHEMATICALFUNCTIONS_HPP
7 #define OPENMPCD_UTILITY_IMPLEMENTATIONDETAILS_MATHEMATICALFUNCTIONS_HPP
8 
10 
11 #include <OpenMPCD/Exceptions.hpp>
15 
16 #include <cmath>
17 
18 namespace OpenMPCD
19 {
20 namespace Utility
21 {
22 namespace MathematicalFunctions
23 {
24 
25 ///@cond
26 
27 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
28 float acos(const float x)
29 {
30  return ::acosf(x);
31 }
32 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
33 double acos(const double x)
34 {
35  return ::acos(x);
36 }
37 template<> OPENMPCD_CUDA_HOST inline
38 long double acos(const long double x)
39 {
40  return ::acosl(x);
41 }
42 
43 
44 
45 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
46 float cos(const float x)
47 {
48  return ::cosf(x);
49 }
50 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
51 double cos(const double x)
52 {
53  return ::cos(x);
54 }
55 template<> OPENMPCD_CUDA_HOST inline
56 long double cos(const long double x)
57 {
58  return ::cosl(x);
59 }
60 
61 
62 
63 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
64 float cospi(const float x)
65 {
66  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
67  return ::cospif(x);
68  #else
69  typedef float T;
70  return MathematicalFunctions::cos(x * MathematicalConstants::pi<T>());
71  #endif
72 }
73 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
74 double cospi(const double x)
75 {
76  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
77  return ::cospi(x);
78  #else
79  typedef double T;
80  return MathematicalFunctions::cos(x * MathematicalConstants::pi<T>());
81  #endif
82 }
83 template<> OPENMPCD_CUDA_HOST inline
84 long double cospi(const long double x)
85 {
86  typedef long double T;
87  return MathematicalFunctions::cos(x * MathematicalConstants::pi<T>());
88 }
89 
90 
91 
92 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
93 float sin(const float x)
94 {
95  return ::sinf(x);
96 }
97 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
98 double sin(const double x)
99 {
100  return ::sin(x);
101 }
102 template<> OPENMPCD_CUDA_HOST inline
103 long double sin(const long double x)
104 {
105  return ::sinl(x);
106 }
107 
108 
109 
110 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
111 float sinpi(const float x)
112 {
113  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
114  return ::sinpif(x);
115  #else
116  typedef float T;
117  return MathematicalFunctions::sin(x * MathematicalConstants::pi<T>());
118  #endif
119 }
120 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
121 double sinpi(const double x)
122 {
123  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
124  return ::sinpi(x);
125  #else
126  typedef double T;
127  return MathematicalFunctions::sin(x * MathematicalConstants::pi<T>());
128  #endif
129 }
130 template<> OPENMPCD_CUDA_HOST inline
131 long double sinpi(const long double x)
132 {
133  typedef long double T;
134  return MathematicalFunctions::sin(x * MathematicalConstants::pi<T>());
135 }
136 
137 
138 
139 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
140 void sincos(const float x, float* const s, float* const c)
141 {
143  s != NULL, OpenMPCD::NULLPointerException);
145  c != NULL, OpenMPCD::NULLPointerException);
146 
147  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
148  return ::sincosf(x, s, c);
149  #else
152  #endif
153 }
154 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
155 void sincos(const double x, double* const s, double* const c)
156 {
158  s != NULL, OpenMPCD::NULLPointerException);
160  c != NULL, OpenMPCD::NULLPointerException);
161 
162  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
163  return ::sincos(x, s, c);
164  #else
167  #endif
168 }
169 template<> OPENMPCD_CUDA_HOST inline
170 void sincos(const long double x, long double* const s, long double* const c)
171 {
173  s != NULL, OpenMPCD::NULLPointerException);
175  c != NULL, OpenMPCD::NULLPointerException);
176 
179 }
180 
181 
182 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
183 void sincospi(const float x, float* const s, float* const c)
184 {
186  s != NULL, OpenMPCD::NULLPointerException);
188  c != NULL, OpenMPCD::NULLPointerException);
189 
190  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
191  return ::sincospif(x, s, c);
192  #else
195  #endif
196 }
197 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
198 void sincospi(const double x, double* const s, double* const c)
199 {
201  s != NULL, OpenMPCD::NULLPointerException);
203  c != NULL, OpenMPCD::NULLPointerException);
204 
205  #if defined(OPENMPCD_PLATFORM_CUDA) && defined(__CUDA_ARCH__)
206  return ::sincospi(x, s, c);
207  #else
210  #endif
211 }
212 template<> OPENMPCD_CUDA_HOST inline
213 void sincospi(const long double x, long double* const s, long double* const c)
214 {
216  s != NULL, OpenMPCD::NULLPointerException);
218  c != NULL, OpenMPCD::NULLPointerException);
219 
222 }
223 
224 
225 
226 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
227 float sqrt(const float x)
228 {
229  return ::sqrtf(x);
230 }
231 template<> OPENMPCD_CUDA_HOST_AND_DEVICE inline
232 double sqrt(const double x)
233 {
234  return ::sqrt(x);
235 }
236 template<> OPENMPCD_CUDA_HOST inline
237 long double sqrt(const long double x)
238 {
239  return ::sqrtl(x);
240 }
241 
242 
243 ///@endcond
244 
245 } //namespace MathematicalFunctions
246 } //namespace Utility
247 } //namespace OpenMPCD
248 
249 #endif //OPENMPCD_UTILITY_IMPLEMENTATIONDETAILS_MATHEMATICALFUNCTIONS_HPP
PlatformDetection.hpp
Exceptions.hpp
OpenMPCD::Utility::MathematicalFunctions::cos
OPENMPCD_CUDA_HOST_AND_DEVICE T cos(const T x)
Returns the cosine of the argument.
OpenMPCD::Utility::MathematicalFunctions::cospi
OPENMPCD_CUDA_HOST_AND_DEVICE T cospi(const T x)
Returns the cosine of the product of the argument and .
OpenMPCD::Utility::MathematicalFunctions::sincos
OPENMPCD_CUDA_HOST_AND_DEVICE void sincos(const T x, T *const s, T *const c)
Computes both the sine and the cosine of the argument.
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
OPENMPCD_DEBUG_ASSERT.hpp
OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE
#define OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE(assertion, ExceptionType)
Definition: OPENMPCD_DEBUG_ASSERT.hpp:76
OPENMPCD_CUDA_HOST
#define OPENMPCD_CUDA_HOST
Denotes a function to be callable from the Host.
Definition: Macros.hpp:20
MathematicalFunctions.hpp
OpenMPCD::Utility::MathematicalFunctions::sincospi
OPENMPCD_CUDA_HOST_AND_DEVICE void sincospi(const T x, T *const s, T *const c)
Computes both the sine and the cosine of the product of the argument and .
MathematicalConstants.hpp
OpenMPCD::Utility::MathematicalFunctions::sqrt
OPENMPCD_CUDA_HOST_AND_DEVICE T sqrt(const T x)
Returns the sqaure root of the argument.
OpenMPCD::Utility::MathematicalFunctions::sinpi
OPENMPCD_CUDA_HOST_AND_DEVICE T sinpi(const T x)
Returns the sine of the product of the argument and .
OpenMPCD::Utility::MathematicalFunctions::acos
OPENMPCD_CUDA_HOST_AND_DEVICE T acos(const T x)
Returns the arc cosine of the argument.
OpenMPCD::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96
OpenMPCD::Utility::MathematicalFunctions::sin
OPENMPCD_CUDA_HOST_AND_DEVICE T sin(const T x)
Returns the sine of the argument.