Hi
I am actually trying to average some values using teensy 4.1.
The result didnt make sense so I started printing stuff. I realised at some point the sign of the sum was flipped ...
Here the result of the printing, l_val2 is the sum and val2 the current value both variables are type long.
val2=-8327505Before l_val2=-2116246172After l_val2=-2124573677 mesCount=255.00
val2=-8315780Before l_val2=-2124573677After l_val2=-2132889457 mesCount=256.00
val2=-8317752Before l_val2=-2132889457After l_val2=-2141207209 mesCount=257.00
val2=-8337528Before l_val2=-2141207209After l_val2=2145422559 mesCount=258.00
val2=-8329891Before l_val2=2145422559After l_val2=2137092668 mesCount=259.00
val2=-8335188Before l_val2=2137092668After l_val2=2128757480 mesCount=260.00
Between mesCount=258.00 and mesCount=259.00 l_val2 has flipped from negative to positive when we are adding a negative value to a negative sum .........
Any ideas ? is there some specific rules as to additions using microcontroller ?
I am actually trying to average some values using teensy 4.1.
The result didnt make sense so I started printing stuff. I realised at some point the sign of the sum was flipped ...
Here the result of the printing, l_val2 is the sum and val2 the current value both variables are type long.
val2=-8327505Before l_val2=-2116246172After l_val2=-2124573677 mesCount=255.00
val2=-8315780Before l_val2=-2124573677After l_val2=-2132889457 mesCount=256.00
val2=-8317752Before l_val2=-2132889457After l_val2=-2141207209 mesCount=257.00
val2=-8337528Before l_val2=-2141207209After l_val2=2145422559 mesCount=258.00
val2=-8329891Before l_val2=2145422559After l_val2=2137092668 mesCount=259.00
val2=-8335188Before l_val2=2137092668After l_val2=2128757480 mesCount=260.00
Between mesCount=258.00 and mesCount=259.00 l_val2 has flipped from negative to positive when we are adding a negative value to a negative sum .........
Any ideas ? is there some specific rules as to additions using microcontroller ?