Isnan suddenly not recognized

I have some code that uses the isnan function.

if (isnan(settingsData.Temperature))
{
    settingsData.Mode = ModeType::Off;
    strcpy(settingsData.Zone, clientIdentifier);
    settingsData.Temperature = 0.0;
}

I’ve been modifying other code in this app (not the function the uses the isnan). It compiled a few times. But then suddenly I started getting a compile error saying

error: ‘isnan’ was not declared in this scope

if (std::isnan(settingsData.Temperature))

But that didn’t work. I then found in the RAW compiler output some cryptic help (wonder why this is not displayed normally) and so then included cmath

#include <cmath>

I also had to continue to prefix with the std namespace as shown earlier for this code to compile.

So, my question is, What happened all of a sudden? Why did I have to include cmath and prefix with the std namespace?

Do this:

#include <math.h>

void loop() {
    isnan(1);
}
2 Likes

Thanks @kennethlimcp. I tried that but I get

fatal error: math: No such file or directory

I’m also wondering why I didn’t need an include (cmath or math) before. This code has been in production for a few months now, without any “math” include.

Hmm… Are you using the Web IDE to compile.

Not sure what’s the change. You can try against the system firmware that you developed on few months back to see if it compiles.

Yes, I am. Sorry, I should have mentioned that earlier. The firmware is the same as earlier (0.62). That is I didn’t change it.

For me this works just fine for 0.6.2 Core, Photon, P1, Electron

#include <math.h>
float f;
void setup() {
  if (isnan(f)) return;
}

Maybe it’s a preprocessor issue again.
Try adding a blank line before the includes or use #pragma SPARK_NO_PREPROCESSOR

In the Wed IDE? When I include I get
fatal error: math: No such file or directory

Opps, my mistake @kennethlimcp and @ScruffR

The “No such file or directory” made me realizes my mistake. I was including
#include <math>
and not
#include <math.h>

Sorry about that. Including math.h does work. Just to be clear, I don’t need to prefix the std namespace either.

However, I still can’t explain how it was working before without the include

1 Like

A similar error I have here: isnan over math.h had been integrated and only with the addition of the softAP example code runs the webIDE on this error:

/usr/local/gcc-arm-embedded/arm-none-eabi/include/c++/4.8.4/cmath:632:5: note:   'std::isnan'
     isnan(_Tp __x)

But for me it is not a serious problem.

That’s not an error but a note.

You may need to post the actual error message.
Note messages are just additional infos for an error to help you get a better understanding why the error was raised.

Thank you for the clarification, ScruffR;
the error is this: error: ‘isnan’ was not declared in this scope
and solved with
#include “math.h” // isnan()
#define isnan