## PKG_ADD: dispatch ("bitshift", "fbitshift", "fixed scalar") ## PKG_ADD: dispatch ("bitshift", "fbitshift", "fixed matrix") ## PKG_ADD: dispatch ("bitshift", "fbitshift", "fixed complex") ## PKG_ADD: dispatch ("bitshift", "fbitshift", "fixed complex matrix") function b = fbitshift (a, k, n) if (!isfixed (a)) error ("fbitshift: argument must be a fixed-point value") else ## Find maximum of is+ds sz = max((a.int + a.dec)(:)) mask = sz + 1; if (nargin == 3) mask = min(n, mask); endif ## Be careful to add back in the signbit and shift left by the decimal x = (abs(real(a.x)) + (real(a.sign) == -1) * (2 .^ real(a.int))) .* (2 .^ real(a.dec)); if (iscomplex (a)) y = (abs(imag(a.x)) + (imag(a.sign) == -1) * (2 .^ imag(a.int))) .* (2 .^ imag(a.dec)); endif if (sz < 8) x = uint8(x); if (iscomplex(a)) y = uint8(y); endif elseif (sz < 16) x = uint16(x); if (iscomplex(a)) y = uint16(y); endif elseif (sz < 32) x = uint32(x); if (iscomplex(a)) y = int32(y); endif else x = uint64(x); if (iscomplex(a)) y = uint64(y); endif endif x = bitshift (x, k, mask); b = fixed (a.int, a.dec, double(x) ./ (2 .^ a.dec)); endif endfunction