comparison toolbox/chop.m @ 2:c124219d7bfa draft

Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author Antonio Pino Robles <data.script93@gmail.com>
date Thu, 07 May 2015 18:36:24 +0200
parents 8f23314345f4
children
comparison
equal deleted inserted replaced
1:e471a92d17be 2:c124219d7bfa
1 function c = chop(x, t)
2 %CHOP Round matrix elements.
3 % CHOP(X, t) is the matrix obtained by rounding the elements of X
4 % to t significant binary places.
5 % Default is t = 24, corresponding to IEEE single precision.
6
7 if nargin < 2, t = 24; end
8 [m, n] = size(x);
9
10 % Use the representation:
11 % x(i,j) = 2^e(i,j) * .d(1)d(2)...d(s) * sign(x(i,j))
12
13 % On the next line `+(x==0)' avoids passing a zero argument to LOG, which
14 % would cause a warning message to be generated.
15
16 y = abs(x) + (x==0);
17 e = floor(log2(y) + 1);
18 c = pow2(round( pow2(x, t-e) ), e-t);