comparison extra/NaN/src/histo_mex.cpp @ 12692:13815b367946 octave-forge

use size_t instead of mwSize/mwIndex whenever possible
author schloegl
date Sat, 12 Sep 2015 14:59:20 +0000
parents f26b1170ea90
children
comparison
equal deleted inserted replaced
12691:6d6285a2a633 12692:13815b367946
43 43
44 #include <math.h> 44 #include <math.h>
45 #include <stdint.h> 45 #include <stdint.h>
46 #include <string.h> 46 #include <string.h>
47 #include "mex.h" 47 #include "mex.h"
48
49 /*
50 math.h has isnan() defined for all sizes of floating point numbers,
51 but c++ assumes isnan(double), causing possible conversions for float and long double
52 */
53 #define ISNAN(a) (a!=a)
48 54
49 55
50 #ifdef tmwtypes_h 56 #ifdef tmwtypes_h
51 #if (MX_API_VER<=0x07020000) 57 #if (MX_API_VER<=0x07020000)
52 typedef int mwSize; 58 typedef int mwSize;
107 } 113 }
108 case mxSINGLE_CLASS: { 114 case mxSINGLE_CLASS: {
109 float f1,f2; 115 float f1,f2;
110 f1 = ((float*)Sort.Table)[ix1]; 116 f1 = ((float*)Sort.Table)[ix1];
111 f2 = ((float*)Sort.Table)[ix2]; 117 f2 = ((float*)Sort.Table)[ix2];
112 z = isnan(f1) - isnan(f2); 118 z = ISNAN(f1) - ISNAN(f2);
113 if (z) break; 119 if (z) break;
114 120
115 if (f1<f2) z = -1; 121 if (f1<f2) z = -1;
116 else if (f1>f2) z = 1; 122 else if (f1>f2) z = 1;
117 // else f1==f2 || (isnan(f1) && isnan(f2)) 123 // else f1==f2 || (isnan(f1) && isnan(f2))
119 } 125 }
120 case mxDOUBLE_CLASS: { 126 case mxDOUBLE_CLASS: {
121 double f1,f2; 127 double f1,f2;
122 f1 = ((double*)Sort.Table)[ix1]; 128 f1 = ((double*)Sort.Table)[ix1];
123 f2 = ((double*)Sort.Table)[ix2]; 129 f2 = ((double*)Sort.Table)[ix2];
124 z = isnan(f1) - isnan(f2); 130 z = ISNAN(f1) - ISNAN(f2);
125 if (z) break; 131 if (z) break;
126 132
127 if (f1<f2) z = -1; 133 if (f1<f2) z = -1;
128 else if (f1>f2) z = 1; 134 else if (f1>f2) z = 1;
129 // else f1==f2 || (isnan(f1) && isnan(f2)) 135 // else f1==f2 || (isnan(f1) && isnan(f2))
176 { 182 {
177 183
178 const mwSize *SZ; 184 const mwSize *SZ;
179 char flag_rows = 0; 185 char flag_rows = 0;
180 char done = 0; 186 char done = 0;
181 mwSize j, k, l; // running indices 187 size_t j, k, l; // running indices
182 const mxArray *W = NULL; 188 const mxArray *W = NULL;
183 double *w = NULL; 189 double *w = NULL;
184 190
185 // check for proper number of input and output arguments 191 // check for proper number of input and output arguments
186 if ((PInputCount <= 0) || (PInputCount > 3)) { 192 if ((PInputCount <= 0) || (PInputCount > 3)) {