future
Newbie level 6
Avoiding overflows in C
Hello,
Analysing this code:
All being chars ranging from 30 to 255, based in the rate of change of the last, it can predict the new sample.. but when it is growing and close to 255 it overflows, also when diminishing close to 0.
I am looking for a way to avoid overflows in this case and others.
Thank you.
Hello,
Analysing this code:
Code:
tperiod2=tperiod1; //
tperiod1=tperiod0; //
tperiod0=wperiod0; //
predict_tmr=(tperiod0+(tperiod0-tperiod1)) + //
(tperiod0-tperiod1-(tperiod1-tperiod2)); //
All being chars ranging from 30 to 255, based in the rate of change of the last, it can predict the new sample.. but when it is growing and close to 255 it overflows, also when diminishing close to 0.
I am looking for a way to avoid overflows in this case and others.
Thank you.