Hello,
I have faced weard problem when playing with arduino 0017. When I'm multiplying with 10000 and placing results to variables values are mixed up somehow. This is not the case if I place same values to variables without any calculation. And If I use + and - calculation this problem doesn't occur either.
I'm newbie with arduino so please tell me if this is something basic.
long temppi = 6000;
Serial.println(temppi);
temppi = 60000;
Serial.println(temppi);
temppi = 600000;
Serial.println(temppi);
temppi = 6000000;
Serial.println(temppi);
Output:
6000
60000
600000
6000000
long temppi = (1000 * 6);
Serial.println(temppi);
temppi = (10000 * 6);
Serial.println(temppi);
temppi = (100000 * 6);
Serial.println(temppi);
temppi = (1000000 * 6);
Serial.println(temppi);
Output:
6000
-5536
600000
6000000
long temppi = 1000 * 6;
Serial.println(temppi);
temppi = 0x2170 * 6;
Serial.println(temppi);
temppi = 100000 * 6;
Serial.println(temppi);
temppi = 1000000 * 6;
Serial.println(temppi);
Output:
6000
-14176
600000
6000000
float temppi = 1000 * 6;
Serial.println(temppi);
temppi = 0x2170 * 6;
Serial.println(temppi);
temppi = 100000 * 6;
Serial.println(temppi);
temppi = 1000000 * 6;
Serial.println(temppi);
Output:
6000.00
-14176.00
600000.00
6000000.00
double temppi = 1000 * 6;
Serial.println(temppi);
temppi = 0x2170 * 6;
Serial.println(temppi);
temppi = 100000 * 6;
Serial.println(temppi);
temppi = 1000000 * 6;
Serial.println(temppi);
Output
6000.00
-14176.00
600000.00
6000000.00
double temppi = 10000 * 6;
temppi = temppi * 10;
Serial.println(temppi);
Output:
-55360.00
double temppi = 10000 * 6;
temppi = temppi / 10;
Serial.println(temppi);
Output:
-553.60
double temppi = 10000 * 6;
temppi = temppi - 10000;
Serial.println(temppi);
Output:
-15536.00
double temppi = 10000 * 6;
Serial.println(temppi);
temppi = 60000;
Serial.println(temppi);
Output:
-5536.00
60000.00
double temppi = 10000 * 6;
Serial.println(temppi);
temppi = 59999 + 1;
Serial.println(temppi);
Output:
-5536.00
60000.00
double temppi = 10000 * 6;
Serial.println(temppi);
temppi = 6 * 10000;
Serial.println(temppi);
temppi = 6000 * 10;
Serial.println(temppi);
-5536.00
-5536.00
-5536.00
double temppi = 10000 * 6;
Serial.println(temppi);
temppi = 2 * 30000;
Serial.println(temppi);
temppi = 2 * 5000;
Serial.println(temppi);
-5536.00
-5536.00
10000.00
double temppi = 10000 * 6;
Serial.println(temppi);
temppi = 2 * 30000;
Serial.println(temppi);
temppi = 2 * 5000;
Serial.println(temppi);
temppi = 4 * 5000;
Serial.println(temppi);
temppi = 6 * 5000;
Serial.println(temppi);
temppi = 8 * 5000;
Serial.println(temppi);
temppi = 10 * 5000;
Serial.println(temppi);
-5536.00
-5536.00
10000.00
20000.00
30000.00
-25536.00
-15536.00
I have also tried many types of variables long, float, double and there is always same results regardless variable type.