5

I have the following sketch:

void setup() {}

void loop() { float af = 4294967040.0; float bf = 4294967240.0; double ad = 4294967040.0; double bd = 4294967040.00001; Serial.println(af); Serial.println(bf); Serial.println(ad); Serial.println(bd); }

The values of af, bf, ad and bd are way smaller than 3.402823466e38 which is the maximum for float values. The values can still be correctly operated with, but the result on the serial monitor however is ovf for bf and bd.

Why is that?

LukasFun
  • 295
  • 1
  • 4
  • 17

1 Answers1

10

It's not the data type, it's the printing routine that sets that limit. In Print.cpp:

227   if (isnan(number)) return print("nan");
228   if (isinf(number)) return print("inf");
229   if (number > 4294967040.0) return print ("ovf");  // constant determined empirically
230   if (number <-4294967040.0) return print ("ovf");  // constant determined empirically

Don't ask why...

Majenko
  • 105,851
  • 5
  • 82
  • 139