00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <limits.h>
00018 #include "mex.h"
00019
00020 void
00021 mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
00022 {
00023 mwSize i, n;
00024 double *pr, *pi;
00025 double inf, nan;
00026
00027
00028 if (nrhs != 1) {
00029 mexErrMsgTxt("One input argument required.");
00030 }
00031 if(nlhs > 1){
00032 mexErrMsgTxt("Too many output arguments.");
00033 }
00034
00035
00036 if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0])) {
00037 mexErrMsgTxt("Input argument must be of type real double.");
00038 }
00039
00040
00041 plhs[0]=mxDuplicateArray(prhs[0]);
00042
00043 pr = mxGetPr(plhs[0]);
00044 pi = mxGetPi(plhs[0]);
00045 n = mxGetNumberOfElements(plhs[0]);
00046 inf = mxGetInf();
00047 nan=mxGetNaN();
00048
00049
00050
00051
00052 for(i=0; i < n; i++) {
00053 if (pr[i] == 0){
00054 pr[i]=nan;
00055 }
00056 else if ( pr[i]>= INT_MAX){
00057 pr[i]=inf;
00058 }
00059 else if (pr[i]<= INT_MIN){
00060 pr[i]=-(inf);
00061 }
00062 }
00063 }
00064
00065
00066
00067
00068