Following idea: I want to add/sub two Q0.31 fixed point numbers. So any addition that results in a value greater than +0.9999999995 or lesser than -1 is not showable in Q0.31. So i want to perform a saturation to the given max/min values. How can i handle this nicely?
My first selfmade idea was something like that:
Code: Select all
signed int result, a, b;
result=a+b;
//check for overflow
if(result<0)
{//a and b were positive?; so result should've been positive to
if(a>0&&b>0)
{
temp=0x7FFFFFFF;//Q0.31 value for +0.9999999995
}
}
else
{//vice versa
if(a<0&&b<0)
{
temp=0x80000001;//Q0.31 value for -1
}
}
I've found the page http://github.xcore.com/doc_tips_and_tr ... point.html where something like:
Code: Select all
overflow = sext(x,24) != x;
Any suggestions for me?^^
Greetings