Virtual Testbed
Ship dynamics simulator for extreme conditions
core/math.hh
1 #ifndef VTESTBED_CORE_MATH_HH
2 #define VTESTBED_CORE_MATH_HH
3 
4 #include <cmath>
5 
6 #include <vtestbed/base/constants.hh>
7 #include <vtestbed/core/types.hh>
8 
10 namespace vtb {
11 
13  namespace core {
14 
15  template <class T>
16  inline bool
17  is_positive_infinity(T x) noexcept {
18  return !std::isfinite(x) && x > T(0);
19  }
20 
21  template <class T>
22  inline bool
23  is_negative_infinity(T x) noexcept {
24  return !std::isfinite(x) && x < T(0);
25  }
26 
33  template <class T,int N>
34  inline T
35  scale(blitz::Array<T,N> x) {
36  auto m = blitz::minmax(x);
37  return m.max - m.min;
38  }
39 
40  template <class T>
41  inline T
42  fma(T a, T x, T b) {
43  return a*x + b;
44  }
45 
46  #if defined(FP_FAST_FMAF) || \
47  defined(__FMA__) || \
48  defined(__FMA4__)
49  template <>
50  inline float
51  fma<float>(float a, float x, float b) {
52  return std::fma(a,x,b);
53  }
54  #endif
55 
56  #if defined(FP_FAST_FMA) || \
57  defined(__FMA__) || \
58  defined(__FMA4__)
59  template <>
60  inline double
61  fma<double>(double a, double x, double b) {
62  return std::fma(a,x,b);
63  }
64  #endif
65 
66  inline float
67  pow2(float x) {
68  return x*x;
69  }
70 
71  inline double
72  pow2(double x) {
73  return x*x;
74  }
75 
76  template <class T>
77  inline std::complex<T>
78  pow2(const std::complex<T>& x) {
79  return x*x;
80  }
81 
82  }
83 
84 }
85 
86 #endif // vim:filetype=cpp
T scale(blitz::Array< T, N > x)
Return the difference between largest and smallest value in the array.
Definition: core/math.hh:35
Main namespace.
Definition: convert.hh:9