Compilation error with some header only libraries

Hi, if I try to use this header only library (including dependencies) then I get this error:

c:/Users/Daniele/Documents/GitHub/ardupilot/modules/PX4Firmware/Build/px4fmu-v4_APM.build/nuttx-export/include/arch/math.h:186:2: error: expected unqualified-id before '(' token
  ((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : \
  ^
compilation terminated due to -Wfatal-errors.

The same exact thing happens with Eigen.

Do you know how to fix this?

1 Like

NuttX has very limited C++ support so many things aren’t supported. I would suggest you try the C version of that library.

Hi @OXINARF, thank you that solves that issue but there is another one.

The compiler seem to treat double as float variables:

error: floating constant exceeds range of 'float' [-Werror=overflow]
    const double r8_huge = 1.79769313486231571E+308;
    ^

I tried changing to ‘long double’ but nothing change.
that would be an issue since the data I will use is 40 bits precise.

EDIT:
Apparently by adding l at the end of the number it takes it as double
const double r8_huge = 1.79769313486231571E+308l;

Yes, it does in PX4 boards. People often forget to add the f suffix to float literals which makes them a double - besides increasing storage it slows down math calculations as PX4 only do fast single float calculation. To prevent that we enabled a compiler option that takes all float literals as floats.

That makes it a long, that then is converted to a double. Given the error I would say the compiler isn’t smart about it and you’ll lose precision. Unfortunately there is no way to write a double literal when the compiler option is enabled, your only way is if you have a way to write the number with a math expression like we have done at:

Thank you for the explanation.

Then I think I could leave those variables as converted long since they seem to be upper and lower bounds…shouldn’t be an issue.

Luckily the data that I need precision with is not set with literals.