unsigned int add (unsigned int a ,unsigned int b)
{
unsigned int res;
unsigned long tmp;
tmp=a+b;
if((a<=32767) && (b<=32767)) // both numbers are positive
{
if (tmp>32767)
{
res=32767;
}
}
else if((a>32767) && (b>32767)) // both numbers are negative
{
if (tmp>32768)
{
res=32768;
}
}
else
{
res=tmp & 0xffff;
}
return(res);
}
unsigned int sub (unsigned int a ,unsigned int b)
{
unsigned int res;
unsigned long tmp;
if((a<=32767) && ( b>=32768) || (a>=32768) && (b<=32767))
{
if(a>b)
{
res=32768;
}
else
{
res=32767;
}
}
else
{
tmp=a-b;
res=tmp & 0xffff;
}
return(res);
}