QMCPACK
math.hpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_STDLIB_PORT_H
14 #define QMCPLUSPLUS_STDLIB_PORT_H
15 #include <config.h>
16 #include <cmath>
17 #include <type_traits>
18 #if defined(HAVE_AMD_LIBM)
19 #include <amdlibm.h>
20 #endif
21 #if defined(HAVE_MASS)
22 #include <mass.h>
23 #endif
24 
25 namespace qmcplusplus
26 {
27 
28 /// sincos function wrapper
29 #if defined(__APPLE__)
30 
31 inline void sincos(double a, double* restrict s, double* restrict c) { ::__sincos(a, s, c); }
32 
33 inline void sincos(float a, float* restrict s, float* restrict c) { ::__sincosf(a, s, c); }
34 
35 #elif defined(HAVE_AMD_LIBM)
36 
37 inline void sincos(double a, double* restrict s, double* restrict c) { ::amd_sincos(a, s, c); }
38 
39 inline void sincos(float a, float* restrict s, float* restrict c) { ::amd_sincosf(a, s, c); }
40 
41 #elif defined(HAVE_SINCOS)
42 
43 inline void sincos(double a, double* restrict s, double* restrict c) { ::sincos(a, s, c); }
44 
45 inline void sincos(float a, float* restrict s, float* restrict c)
46 {
47 #if defined(HAVE_MASS)
48  // there is no sincosf in libmass
49  // libmass sincos is faster than libm sincosf
50  double ds, dc;
51  ::sincos((double)a, &ds, &dc);
52  *s = ds;
53  *c = dc;
54 #else
55  ::sincosf(a, s, c);
56 #endif
57 }
58 
59 #else // fallback
60 
61 template<typename T>
62 inline void sincos(T a, T* restrict s, T* restrict c)
63 {
64  *s = std::sin(a);
65  *c = std::cos(a);
66 }
67 
68 #endif
69 
70 /** return i^n
71  *
72  * std::pow(int,int) is not standard
73  */
74 inline int pow(int i, int n) { return static_cast<int>(std::pow(static_cast<double>(i), n)); }
75 
76 template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
77 inline bool iszero(T a)
78 {
79  return std::fpclassify(a) == FP_ZERO;
80 }
81 
82 /** return true if the value is NaN.
83  * std::isnan can be affected by compiler the -ffast-math option and return true constantly.
84  * The customized qmcplusplus::isnan should be always effective.
85  * This requires its definition compiled without -ffast-math.
86  */
87 bool isnan(float);
88 bool isnan(double);
89 
90 /** return true if the value is finite.
91  * std::isfinite can be affected by compiler the -ffast-math option and return true constantly.
92  * The customized qmcplusplus::isnan should be always effective.
93  * This requires its definition compiled without -ffast-math.
94  */
95 bool isfinite(float);
96 bool isfinite(double);
97 
98 /** return true if the value is Inf.
99  * std::isinf can be affected by compiler the -ffast-math option and return true constantly.
100  * The customized qmcplusplus::isnan should be always effective.
101  * This requires its definition compiled without -ffast-math.
102  */
103 bool isinf(float);
104 bool isinf(double);
105 
106 } // namespace qmcplusplus
107 
108 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
MakeReturn< UnaryNode< FnSin, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sin(const Vector< T1, C1 > &l)
int pow(int i, int n)
return i^n
Definition: math.hpp:74
bool isfinite(float a)
return true if the value is finite.
Definition: math.cpp:21
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
MakeReturn< UnaryNode< FnCos, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t cos(const Vector< T1, C1 > &l)
bool iszero(T a)
Definition: math.hpp:77
void sincos(T a, T *restrict s, T *restrict c)
sincos function wrapper
Definition: math.hpp:62
bool isinf(float a)
return true if the value is Inf.
Definition: math.cpp:24
bool isnan(float a)
return true if the value is NaN.
Definition: math.cpp:18