INTLABと互換性のある setround() が用意されている。
以下に引用するが、feature() という関数を用いている。
(feature() については、 “Undocumented feature() function” を見よ。)
function setround(rnd)
% Set rounding mode
switch rnd
case -1 % Rounding to -Inf
feature('setround',-inf)
case 0 % Rounding to nearest
feature('setround',0.5)
case 1 % Rounding to +Inf
feature('setround',inf)
case 2 % Roundint towards zero
feature('setround',0)
otherwise
error('rnd = -1,0,1 or 2')
end
|
MATLAB で丸めモードを変更するには、 もう1つ system_dependent() という手がある。 どうも現在の Intval はこれを使っているのかも。
system_dependent('setround',inf)
system_dependent('setround',-inf)
system_dependent('setround',0.5)
|
feature() にしても、 system_dependent() にしても、 ずっと使い続けられるのかは不明である。
桂田 祐史