diff --git a/matrix/stdlib_imports.hpp b/matrix/stdlib_imports.hpp index 4d24b814cf..efeba31322 100644 --- a/matrix/stdlib_imports.hpp +++ b/matrix/stdlib_imports.hpp @@ -15,6 +15,42 @@ namespace matrix { +#if defined(__PX4_NUTTX) +/* + * NuttX has no usable C++ math library, so we need to provide the needed definitions here manually. + */ +#define MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(name) \ + inline float name(float x) { return ::name##f(x); } \ + inline double name(double x) { return ::name(x); } \ + inline long double name(long double x) { return ::name##l(x); } + +#define MATRIX_NUTTX_WRAP_MATH_FUN_BINARY(name) \ + inline float name(float x, float y) { return ::name##f(x, y); } \ + inline double name(double x, double y) { return ::name(x, y); } \ + inline long double name(long double x, long double y) { return ::name##l(x, y); } + +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(fabs) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(log) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(log10) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(exp) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(sqrt) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(sin) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(cos) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(tan) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(asin) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(acos) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(atan) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(sinh) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(cosh) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(tanh) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(ceil) +MATRIX_NUTTX_WRAP_MATH_FUN_UNARY(floor) + +MATRIX_NUTTX_WRAP_MATH_FUN_BINARY(pow) +MATRIX_NUTTX_WRAP_MATH_FUN_BINARY(atan2) + +#else // Not NuttX, using the C++ standard library + using std::abs; using std::div; using std::fabs; @@ -40,7 +76,7 @@ using std::frexp; using std::ldexp; using std::modf; -#if (__cplusplus >= 201103L) && !defined(__PX4_NUTTX) +# if (__cplusplus >= 201103L) using std::imaxabs; using std::imaxdiv; @@ -88,6 +124,7 @@ using std::islessequal; using std::islessgreater; using std::isunordered; +# endif #endif }