Salve,
sto leggendo un libro e mi sono trovato di fronte questo sorgente:
void loop()
{
value = value - 0.1;
// reduce value by 0.1 each time through the loop
if( value == 0)
Serial.println("The value is exactly zero");
else if(almostEqual(value, 0)) {
Serial.print("The value ");
Serial.print(value,7); // print to 7 decimal places
Serial.println(" is almost equal to zero");
} else
Serial.println(value);
delay(100);
}
// returns true if the difference between a and b is small
// set value of DELTA to the maximum difference considered to be equal
boolean almostEqual(float a, float b)
{
const float DELTA = .00001; // max difference to be almost equal
if (a == 0) return fabs(b) <= DELTA;
if (b == 0) return fabs(a) <= DELTA;
return fabs((a - b) / max(fabs(a), fabs(b))) <= DELTA ;
}
Ho diversi dubbi:
1)eseguendolo non ho capito perchè il valore non è mai 0.00 (quando value=0.10 sottraendo viene -0.0000001)
2)return fabs(b) <= DELTA; quel <= cosa vuol dire?
Grazie a chi mi aiuterà!