Hello,
I write a software that read and write number in the EEPROM section.
The first operation read all number.
The second operation check for every number (int or float) that the value is in the correct range.
But, when before the software write in the EEProm, the value are not initialised.
So, if the software read uninitialised number, it can be all but not a number.
I would like to check this case, because in this case I can check if the value is lower than xx or greather than yy.
How can I test if there is a number in the assigned value ?
If I print some value with Serial.print, sometime I can read : NAN
In this case, I can't check if the value is in the range with
If (value < xx or value > yy).
So I have to add a check if the value is a number or not (NAN -> not a number).
I reed the structure with the small header in attachment: EEPROMAnything.h
Many thanks for your help.
an integer can never be NaN, all possible bit combinations represent numbers.
for a float it is different, there exist two functions you should know that they exist
EEPROM_readAnything(addr, &config);
if ( isnan(config.c) );
{
Serial.println("Eeprom not initialized?");
}
else if (isInf(config.c) > 0)
{
Serial.println("extreme positive");
}
else if (isinf(config.c) < 0 )
{
Serial.println("more negative than this does not exist");
}
Vorms:
How can I test for example if config.a is a normal number or a NAN ?
if (config.c == 0xFFFFFFFFFFFFFFFF)
Sorry but that does not work
void setup()
{
Serial.begin(115200);
Serial.println("Start ");
float f = log(-1); // you can't take the logarithm of a negative number in R
Serial.println(f,7);
Serial.println(f == 0xFFFFFFFF);
Serial.println(isnan(f));
}
void loop()
{
}