Arduino calculating wrongly???

Dear all,

when I worked on calculations based on millis() I discovered something very strange. Have a look to this sketch and the result. “b” is correct, “a” not. Any ideas?

bstRgds, Olaf

Crazy_Calc_Result.jpg

When someone posts "strange results", pound to a penny it's the wrong data type. Please post your code.

Most Arduinos uses 16 bit int type by default, so if you want numbers larger than 32767 you have to specify long datatypes for variables and constants:

  long millis_per_day = 24 * 60 * 60 * 1000L ;  // long constant forces long calculations
  Serial.println (millis_per_day) ;

th10gt:
Have a look to this sketch

You didn’t post any “sketch”, you posted “pictures”.

If you want to show a sketch, post a sketch!

An please post the code “inline” in your posting, included in code-tags.
Use the “</>” icon in the message editor to include code-tags in your message.

th10gt: Dear all,

when I worked on calculations based on millis() I discovered something very strange. Have a look to this sketch and the result. "b" is correct, "a" not. Any ideas?

bstRgds, Olaf

The formula for variable "a" was performed using 16 Bit Math (default). The formulas used for variable b were performed using 32 Bit Math.

Your answers are correct, for the code that you compiled.