?? sfl.m
字號:
%% PURPOSE:% SFL computes the floating point represenation of x.% This is just a simulation of what the floating point % represenation of x would be. (sfl = Simulate FLoating % point)% % It assumed that the base is 10 and that there% is no restriction on the exponent range.% The mantissa length is m, i.e. if%% - e% x = d . d d d ..... d d ... * 10 ,% 0 1 2 3 m-1 m%% then% e% sfl(x) = d . d d d ..... d * 10 .% 0 1 2 3 m-1 %% The m-th digit of sfl(x) may be different from the% m-th digit of. If FLOATING POINT ARITHMETIC is used, % then% -% d = d if d <= 4 , % m-1 m m% -% d = d +1 if d => 5 .% m-1 m m%% If CHOPPED ARITHMETIC is used, then% -% d = d . % m m % % % CALLING SEQUENCE:%% function [flx] = sfl( x, m, arith )% % INPUT PARAMETERS:% % x real% floating point operation% % m integer% mantissa length% % arith string% arith = 'c' chopped arithmetic% arith = 'r' rounded arithmetic% %%%%% Matthias Heinkenschloss% Department of Computational and Applied Mathematics% Rice University% Feb 12, 2001%% function [flx] = sfl( x, m, arith )% The following internal variables are used:%% iexp is the exponent e, % xm is the mantissa (with leading 0.)% xrd is the rounded value of x (rounded to m digits)% xchp is the chopped value of x (chopped to m digits)% if x = 0. we don't have to do anythingif( x == 0. ) flx = 0.; returnend% Determine the exponenttmp = log10(abs(x));if ( tmp > 0. ) ixexp = 1 + fix( tmp );else ixexp = fix( tmp );end % determine the mantissaxm = x * 10^(-ixexp);if( xm > 0 ) xrd = fix( xm * 10^m + 0.5 ) * 10.^(ixexp-m); xchp = fix( xm * 10^m ) * 10^(ixexp-m);endif( xm < 0 ) xrd = fix( xm * 10^m - 0.5 ) * 10.^(ixexp-m); xchp = fix( xm * 10^m ) * 10^(ixexp-m);endif( arith == 'c' ) flx = xchp;endif( arith == 'r' ) flx = xrd;end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -