NaN handling bug

I am not sure what is the right forum to report this, but it seems that the latest ARM Compiler (6.14) bundled with the Mbed Studio 1.1.0 has a NaN handling bug. The following code fragment
float a = 0.0f;
float aa = nanf("");
printf(“Nans are %d and %d\n”, isnan(aa), isnan(a));
gives the output
Nans are 0 and 0
which is incorrect (it should be Nans are 1 and 0). Previous version of the Mbed Studio ARM Compiler (I suppose it was version 6.13) gave the correct result. Platform used to test the code was NXP mbed LPC1768 dev board.

its not a bug, its a feature :slight_smile:

minimal_printf is default for mbed6.

I suppose that the problem is not with the printf but rather with the isnan() function. It returns integer value which should be printed correctly even using minimal printf (And I have the “target.printf_lib”: “std” line in mbed_app.json). I assume that the isnan() returns 0 incorrectly even if the argument is a NaN number.


I do not know what version of compiler currently use the Online Compiler or MbedStudio Oline but the output is Nans are 1 and 0 from both.
But when it is compiled with the MbedStudio IDE, the output is Nans are 0 and 0.
So I can confirm different behavior.

Maybe @JoeA can help.

BR, Jan

Hi Jarkko, Jan

I’ve just checked and I can confirm that this difference in behavior is due to the Arm Compiler version update from 6.13 to 6.14.

Output in ARMC 6.13:
Nans are 1 and 0
Output in ARMC 6.14:
Nans are 0 and 0

I’ll raise this change internally and find out if it was expected.

Online Compiler vs Mbed Studio
There are a few differences between browser and desktop environments:

  • Online build system used in Online Compiler supports multiple versions of Arm Compiler. During a compilation, a version is chosen based on Mbed OS version inside of the program. Mbed Studio desktop on the other hand is always using a single version of Arm Compiler 6 for all programs. That version is being updated with Studio releases (currently 6.14.0 is being used)
  • Mbed Studio on desktop supports multiple profiles. Including custom profiles defined by user. Debug profile is used by default. Online compiler on the other hand does not support profile change. Develop profile is used.

We are investigating the addition of profiles and compiler versions selection in-browser version of Studio. It is possible that it will be supported at some point. The decision hasn’t been made yet.

Arek - Mbed Studio team

1 Like

HI @arekzaluski,

A month later have you find information about this change?

Any solution to bypass this bug with NaN?

For information the test (var != var) bug like isnan(var) and return always false.


Hi @mimicque, @JohnnyK, @YSI,

Apologies. I forgot to answer you. I’ve reached out to Arm Compiler team. I was told that this is a default optimization added in Arm Compiler 6.14 .
-fhonor-nans and -ffp-mode=full can be used to tell armclang compiler to generate code that takes NaNs into account. You should be able to add them in Mbed OS profile for ARMC6.
You can find more about profiles management here:

Arek - Mbed Studio team

1 Like

Thanks for the information. It seems that -fhonor-nans command line option is enough to get the NaNs working (it increases the size of the program about 3Kbytes in LPC1768 environment). Curiously, I was not able to find any information about the -fhonor-nans option, but it works!

BTW: Mbed OS profile is located in the directory ./mbed-os/tools/profiles

Regards, Jarkko

1 Like