integer math, where are the intermediate values stored? limitations?
hello all,
i have silly question.
i have equation say:
int result = (200 * 8 * 33) / 1000;
a signed integer can of course hold +/- 32768. 'result' should 52 , should fit fine. keep getting strange math errors in equations , think because (200 * 8 * 33) part if results in 52800 big fit in integer.
so questions are, thinking correct? of intermediate arithmetic crunches stored in register same size data type assigned to?
and how around this? if (200 *
/1000 * 33 or (200 * 33)/1000 * 8 rounding error grows high.
do need use long though i'm storing max of 52?
thanks!
i have silly question.
i have equation say:
int result = (200 * 8 * 33) / 1000;
a signed integer can of course hold +/- 32768. 'result' should 52 , should fit fine. keep getting strange math errors in equations , think because (200 * 8 * 33) part if results in 52800 big fit in integer.
so questions are, thinking correct? of intermediate arithmetic crunches stored in register same size data type assigned to?
and how around this? if (200 *
![cool 8)](https://forum.arduino.cc/smileys/arduino/cool.gif)
do need use long though i'm storing max of 52?
thanks!
quote
is of intermediate arithmetic crunches stored in register same size data type assigned to?
no. intermediate results stored in register size of largest data value involved. since values ints, int register used. 52,800 not fit in int.
you can change register size casting or adding l or ul end of 1 or more of values.
Arduino Forum > Using Arduino > Programming Questions > integer math, where are the intermediate values stored? limitations?
arduino
Comments
Post a Comment