% PURPOSE: % SFLOP simulates a floating point operation % % x op y where op = +, -, *, / % % In chopping or rounding arithmetic using an % m digit mantissa, base 10, and an unrestricted % exponent range. (sflop: Simulate FLOating Point % operation.) For more details on the how the floating % point representation of a number is computed see % the function sfl. % % % CALLING SEQUENCE: % % function [res] = sflop( x, y, m, arith, op ) % % INPUT: % % x real % argument in the floating point operation % % y real % argument in the floating point operation % % m integer % mantissa length % % arith string % arith = 'c' chopped arithmetic % arith = 'r' rounded arithmetic % % op string % type of floating point operation % op = '+' or '-' or '*' or '/' % % % OUTPUT: % % res real % result of the floating point operation % % % % % Matthias Heinkenschloss % Department of Computational and Applied Mathematics % Rice University % Feb 12, 2001 % % function [res] = sflop( x, y, m, arith, op ) % compute floating point represenation of x and y xfl = sfl( x, m, arith); yfl = sfl( y, m, arith); % perform operation to 'full' accuracy if( op == '+' ) z = xfl + yfl; end if( op == '-' ) z = xfl - yfl; end if( op == '*' ) z = xfl .* yfl; end if( op == '/' ) z = xfl ./ yfl; end % round/chopp the result res = sfl( z, m, arith);