www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgprecfloat/physresolve.m
function PhysValuesOut = physresolve(Prec, PhysValuesIn) %PHYSRESOLVE Resolve to achievable physical values. % % PhysValuesOut = PHYSRESOLVE(FLOATPREC, PhysValuesIn) converts unresolved % physical values PhysValuesIn to resolved physical values PhysValuesOut % using the achievable resolution specififed by the cgprecfloat object % FLOATPREC. % Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc. if (Prec.mbits == 52 && Prec.ebits == 11 ) ||... (Prec.mbits == 23 && Prec.ebits == 8) % FLOATPREC is an IEEE single or double precision object % Error check on PhysValuesIn PhysValuesOut = i_check(Prec, PhysValuesIn, 'PhysValues'); % Get physical range from the cgprecfix object FLOATPREC PhysRange = get(Prec, 'PhysRange'); % The minimum achievable value is PhysRange(1) PhysValuesOut(PhysValuesIn<PhysRange(1)) = PhysRange(1); % The maximum achievable value is PhysRange(2) PhysValuesOut(PhysValuesIn>PhysRange(2)) = PhysRange(2); if Prec.mbits == 23 % IEEE single precision PhysValuesOut = double(single(PhysValuesOut)); % Otherwise it is IEEE double precision: no change to PhysValuesOut end else % Convert physical values to hardware values HWValues = phys2hw(Prec, PhysValuesIn); % Convert hardware values back to physical values PhysValuesOut = hw2phys(Prec, HWValues); end % ------------------------------------------------------------------------- function out = i_check(Prec, in, VarName) % Check input variables switch VarName case 'PhysValues' if pCheckNumeric(Prec, in, true, VarName) % PhysValues is valid out = in; end end