PX4 Firmware
PX4 Autopilot Software http://px4.io
stdlib_imports.hpp
Go to the documentation of this file.
1 /**
2  * @file stdlib_imports.hpp
3  *
4  * This file is needed to shadow the C standard library math functions with ones provided by the C++ standard library.
5  * This way we can guarantee that unwanted functions from the C library will never creep back in unexpectedly.
6  *
7  * @author Pavel Kirienko <pavel.kirienko@zubax.com>
8  */
9 
10 #pragma once
11 
12 #include <cmath>
13 #include <cstdlib>
14 #include <inttypes.h>
15 
16 #ifndef M_PI
17 #define M_PI 3.14159265358979323846
18 #endif
19 #ifndef M_TWOPI
20 #define M_TWOPI (M_PI * 2.0)
21 #endif
22 
23 namespace matrix {
24 
25 #if !defined(FLT_EPSILON)
26 #define FLT_EPSILON __FLT_EPSILON__
27 #endif
28 
29 #if defined(__PX4_NUTTX)
30 /*
31  * NuttX has no usable C++ math library, so we need to provide the needed definitions here manually.
32  */
33 #define MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(name) \
34  inline float name(float x) { return ::name##f(x); } \
35  inline double name(double x) { return ::name(x); } \
36  inline long double name(long double x) { return ::name##l(x); }
37 
38 #define MATRIX_NUTTX_WRAP_MATH_FUN_BINARY(name) \
39  inline float name(float x, float y) { return ::name##f(x, y); } \
40  inline double name(double x, double y) { return ::name(x, y); } \
41  inline long double name(long double x, long double y) { return ::name##l(x, y); }
42 
43 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(fabs)
44 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(log)
45 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(log10)
46 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(exp)
47 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(sqrt)
48 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(sin)
49 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(cos)
50 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(tan)
51 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(asin)
52 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(acos)
53 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(atan)
54 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(sinh)
55 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(cosh)
56 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(tanh)
57 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(ceil)
58 MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(floor)
59 
60 MATRIX_NUTTX_WRAP_MATH_FUN_BINARY(pow)
61 MATRIX_NUTTX_WRAP_MATH_FUN_BINARY(atan2)
62 
63 #else // Not NuttX, using the C++ standard library
64 
65 using std::abs;
66 using std::div;
67 using std::fabs;
68 using std::fmod;
69 using std::exp;
70 using std::log;
71 using std::log10;
72 using std::pow;
73 using std::sqrt;
74 using std::sin;
75 using std::cos;
76 using std::tan;
77 using std::asin;
78 using std::acos;
79 using std::atan;
80 using std::atan2;
81 using std::sinh;
82 using std::cosh;
83 using std::tanh;
84 using std::ceil;
85 using std::floor;
86 using std::frexp;
87 using std::ldexp;
88 using std::modf;
89 
90 # if (__cplusplus >= 201103L)
91 
92 using std::remainder;
93 using std::remquo;
94 using std::fma;
95 using std::fmax;
96 using std::fmin;
97 using std::fdim;
98 using std::nan;
99 using std::nanf;
100 using std::nanl;
101 using std::exp2;
102 using std::expm1;
103 using std::log2;
104 using std::log1p;
105 using std::cbrt;
106 using std::hypot;
107 using std::asinh;
108 using std::acosh;
109 using std::atanh;
110 using std::erf;
111 using std::erfc;
112 using std::tgamma;
113 using std::lgamma;
114 using std::trunc;
115 using std::round;
116 using std::nearbyint;
117 using std::rint;
118 using std::scalbn;
119 using std::ilogb;
120 using std::logb;
121 using std::nextafter;
122 using std::copysign;
123 using std::fpclassify;
124 using std::isfinite;
125 using std::isinf;
126 using std::isnan;
127 using std::isnormal;
128 using std::signbit;
129 using std::isgreater;
130 using std::isgreaterequal;
131 using std::isless;
132 using std::islessequal;
133 using std::islessgreater;
134 using std::isunordered;
135 
136 # endif
137 #endif
138 
139 }
Dual< Scalar, N > acos(const Dual< Scalar, N > &a)
Definition: Dual.hpp:309
Dual< Scalar, N > atan(const Dual< Scalar, N > &a)
Definition: Dual.hpp:317
Dual< Scalar, N > ceil(const Dual< Scalar, N > &a)
Definition: Dual.hpp:203
Dual< Scalar, N > asin(const Dual< Scalar, N > &a)
Definition: Dual.hpp:301
Dual< Scalar, N > cos(const Dual< Scalar, N > &a)
Definition: Dual.hpp:286
Dual< Scalar, N > tan(const Dual< Scalar, N > &a)
Definition: Dual.hpp:293
Dual< Scalar, N > fmod(const Dual< Scalar, N > &a, Scalar mod)
Definition: Dual.hpp:217
Dual< Scalar, N > abs(const Dual< Scalar, N > &a)
Definition: Dual.hpp:196
Dual< Scalar, N > sin(const Dual< Scalar, N > &a)
Definition: Dual.hpp:279
Dual< Scalar, N > floor(const Dual< Scalar, N > &a)
Definition: Dual.hpp:210
Dual< Scalar, N > sqrt(const Dual< Scalar, N > &a)
Definition: Dual.hpp:188
Dual< Scalar, N > atan2(const Dual< Scalar, N > &a, const Dual< Scalar, N > &b)
Definition: Dual.hpp:325