Underflow issue... Again :-(

mortifyu

New Member
Hi Guru's,

How to get around this resultant underflow issue? I looked around the forum, but did not find the (simple I am sure) answer.


Code:
w0= 5
w1=18

w0=w0 - w1 min 0


end
w0 and w1 can and do vary with reference to ADC inputs.

So the desired calculation is that I would like be able to deduct w1 (a potentially higher value than w0) from w0 without the result underflowing below 1 or preferably 0.

I know I could first up say something like:
Code:
if w1>w0 then
   w0=0
endif
But... Is there a better way?



Thanks in advance!


Regards,
Mort.
 

Aries

New Member
Code:
w0 = w0 min w1 - w1
will ensure that your result is never "negative".
The min gives a value which is the maximum of w0 and w1. This is never less than w1, and so the result is never less than zero.
 

mortifyu

New Member
Thank you Gentlemen, most appreciated.

I see you guys are quick to maintain Super-Star status around these parts. ;)



Kind regards,
Mort.
 
Top