/* --------------------------------------------------------------- File Name: round.c Author: James E. Stine Dept. of EECS Lehigh University Last Revised: 6/13/97 Purpose: This file contains support for the rounding modes. Change the Rounding Mode (Solaris UltraSparc) (0) Round to Nearest Even (1) Round to Zero (2) Round to Positive Infinity (3) Round ot Negative Infinity Usage: roundj([0-3]) where 0-3 represents the above rounding-mode on a SPARC Copyright: Lehigh University 1997, 1998, 1999 Use without express written consent is strictly forbidden. Violators shall be persecuted at the highest extent of the law. -------------------------------------------------------------------*/ #include "mex.h" #include "matrix.h" #include "round.h" #define INPUT_ARRAY prhs[0] void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { mxArray *char_array; int rounding_mode; /* * GOOD TECHNIQUE: Make sure the I/O you're expecting is correct. * * You will always be able to reference plhs[0]. * If the user does not assign a left hand * argument, the return argument will be assigned * to ANS. */ if(nrhs!=1) { mexErrMsgTxt("Usage : round(value)\n"); } rounding_mode = mxGetScalar(INPUT_ARRAY); if (rounding_mode == 0) RND_NEAR(); else if (rounding_mode == 1) RND_ZERO(); else if (rounding_mode == 2) RND_UP(); else if (rounding_mode == 3) RND_DOWN(); else { mexPrintf("You have entered an incorrect choice\n"); mexPrintf("Pleae enter a choice between 0 and 3\n"); mexPrintf("0 = Round-to-nearest-Even\n"); mexPrintf("1 = Round-to-Zero (truncation)\n"); mexPrintf("2 = Round-to-Positive-Infinity\n"); mexPrintf("3 = Round-to-Negative-Infinity\n\n"); } }