Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
NuttX math lib workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Mar 17, 2017
1 parent 14e9465 commit 8ef2527
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion matrix/stdlib_imports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -88,6 +124,7 @@ using std::islessequal;
using std::islessgreater;
using std::isunordered;

# endif
#endif

}

0 comments on commit 8ef2527

Please sign in to comment.