function [u,i] = fpadd(a,b,Nu,Qu)

i=0;
% fixed-point addition
u = a+b;

% handle overflow
% check most positive value
while u>(2^(Nu-1)-1)/2^Qu,
  u = (u*2^Qu-2^Nu)/2^Qu;
  i = 1;
end

% check most negative value
while u<-2^(Nu-1)/2^Qu,
  u = (u*2^Qu+2^Nu)/2^Qu;
  i = 1;
end


% throw away any lost precision
% note that "floor" command rounds toward -inf
% which is what would happen on the C6713 if we
% just threw away bits
u = floor(u*2^Qu)/(2^Qu);