Changeset 36375 for trunk/Ohana/src/opihi/lib.shell/stack_math.c
- Timestamp:
- Dec 10, 2013, 2:55:11 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
Ohana (modified) (1 prop)
-
Ohana/src/opihi (modified) (1 prop)
-
Ohana/src/opihi/lib.shell/stack_math.c (modified) (61 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
trunk/Ohana
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20130904/Ohana (added) merged: 36144-36145,36150-36151,36160,36194-36195,36236,36251,36274,36286,36369
- Property svn:mergeinfo changed
-
trunk/Ohana/src/opihi
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20130904/Ohana/src/opihi (added) merged: 36144-36145,36150-36151,36160,36195,36236,36251,36274,36286,36369
- Property svn:mergeinfo changed
-
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r34342 r36375 6 6 */ 7 7 8 // XXX we temporarily drop the concept of using one of the temporary input vectors for 9 // the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors 10 // as well as their temporary state 11 12 int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 8 int SSS_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) { 9 10 char line[512]; // this is only used to report an error 11 12 // set up the possible operations : int OP int -> int, all else yield float 13 // OP is the operation performed on *M1 and *M2 14 # define SSS_FUNC(OP) { \ 15 if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT) && (V3->type == ST_SCALAR_FLT)) { \ 16 opihi_flt M1 = V1[0].FltValue; \ 17 opihi_flt M2 = V2[0].FltValue; \ 18 opihi_flt M3 = V3[0].FltValue; \ 19 OUT[0].type = ST_SCALAR_FLT; \ 20 OUT[0].FltValue = OP; \ 21 break; \ 22 } \ 23 if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT) && (V3->type == ST_SCALAR_INT)) { \ 24 opihi_int M1 = V1[0].IntValue; \ 25 opihi_int M2 = V2[0].IntValue; \ 26 opihi_int M3 = V3[0].IntValue; \ 27 OUT[0].type = ST_SCALAR_INT; \ 28 OUT[0].IntValue = OP; \ 29 break; \ 30 } \ 31 } 32 33 switch (op[0]) { 34 case '?': SSS_FUNC(M1 ? M2: M3); 35 default: 36 snprintf (line, 512, "error: op %c not defined!", op[0]); 37 push_error (line); 38 return (FALSE); 39 } 40 # undef SSS_FUNC 41 42 clear_stack (V1); 43 clear_stack (V2); 44 clear_stack (V3); 45 return (TRUE); 46 47 } 48 49 int VVV_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) { 13 50 14 51 int i, Nx; … … 19 56 return (FALSE); 20 57 } 58 if (V1[0].vector[0].Nelements != V3[0].vector[0].Nelements) { 59 return (FALSE); 60 } 21 61 22 62 Nx = V1[0].vector[0].Nelements; … … 24 64 // create the output vector guaranteed to be temporary until the very end 25 65 OUT[0].vector = InitVector (); 26 OUT[0].type = 'v'; 66 OUT[0].type = ST_VECTOR_TMP; 67 68 // set up the possible operations : int OP int -> int, all else yield float 69 // OP is the operation performed on *M1 and *M2 70 # define VVV_FUNC(OP) { \ 71 if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \ 72 CopyVector (OUT[0].vector, V1[0].vector); \ 73 opihi_flt *M1 = V1[0].vector[0].elements.Flt; \ 74 opihi_flt *M2 = V2[0].vector[0].elements.Flt; \ 75 opihi_flt *M3 = V3[0].vector[0].elements.Flt; \ 76 opihi_flt *out = OUT[0].vector[0].elements.Flt; \ 77 for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) { \ 78 *out = OP; \ 79 } \ 80 break; \ 81 } \ 82 if ((V1->vector->type == OPIHI_INT) && (V2->vector->type == OPIHI_INT) && (V3->vector->type == OPIHI_INT)) { \ 83 CopyVector (OUT[0].vector, V1[0].vector); \ 84 opihi_int *M1 = V1[0].vector[0].elements.Int; \ 85 opihi_int *M2 = V2[0].vector[0].elements.Int; \ 86 opihi_int *M3 = V3[0].vector[0].elements.Int; \ 87 opihi_int *out = OUT[0].vector[0].elements.Int; \ 88 for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) { \ 89 *out = OP; \ 90 } \ 91 break; \ 92 } \ 93 } 94 95 switch (op[0]) { 96 case '?': VVV_FUNC(*M1 ? *M2: *M3); 97 default: 98 snprintf (line, 512, "error: op %c not defined!", op[0]); 99 push_error (line); 100 return (FALSE); 101 } 102 # undef VVV_FUNC 103 104 /** free up any temporary buffers: **/ 105 106 if (V1[0].type == ST_VECTOR_TMP) { 107 free (V1[0].vector[0].elements.Ptr); 108 free (V1[0].vector); 109 } 110 if (V2[0].type == ST_VECTOR_TMP) { 111 free (V2[0].vector[0].elements.Ptr); 112 free (V2[0].vector); 113 } 114 if (V3[0].type == ST_VECTOR_TMP) { 115 free (V3[0].vector[0].elements.Ptr); 116 free (V3[0].vector); 117 } 118 /* at the end, V1 and V2 are deleted only if they were temporary */ 119 120 clear_stack (V1); 121 clear_stack (V2); 122 clear_stack (V3); 123 return (TRUE); 124 125 } 126 127 int MMM_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) { 128 129 int i, Nx, Ny; 130 float *out, *M1, *M2, *M3; 131 char line[512]; // this is only used to report an error 132 133 Nx = V1[0].buffer[0].matrix.Naxis[0]; 134 Ny = V1[0].buffer[0].matrix.Naxis[1]; 135 136 if (V1[0].type == ST_MATRIX_TMP) { /** use V1 as temp buffer **/ 137 OUT[0].buffer = V1[0].buffer; 138 V1[0].type = ST_MATRIX; /* prevent it from being freed below */ 139 } else { 140 if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/ 141 OUT[0].buffer = V2[0].buffer; 142 V2[0].type = ST_MATRIX; /* prevent it from being freed below */ 143 } else { /* no spare temp buffer */ 144 OUT[0].buffer = InitBuffer (); 145 CopyBuffer (OUT[0].buffer, V1[0].buffer); 146 } 147 } 148 OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/ 149 150 M1 = (float *)V1[0].buffer[0].matrix.buffer; 151 M2 = (float *)V2[0].buffer[0].matrix.buffer; 152 M3 = (float *)V3[0].buffer[0].matrix.buffer; 153 out = (float *)OUT[0].buffer[0].matrix.buffer; 154 155 # define MMM_FUNC(OP) \ 156 for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++, M3++) { \ 157 *out = OP; \ 158 } \ 159 break; 160 161 switch (op[0]) { 162 case '?': MMM_FUNC(*M1 ? *M2: *M3); 163 default: 164 snprintf (line, 512, "error: op %c not defined!", op[0]); 165 push_error (line); 166 return (FALSE); 167 } 168 # undef MMM_FUNC 169 170 /** free up any temporary buffers: **/ 171 172 if (V1[0].type == ST_MATRIX_TMP) { 173 free (V1[0].buffer[0].header.buffer); 174 free (V1[0].buffer[0].matrix.buffer); 175 free (V1[0].buffer); 176 } 177 if (V2[0].type == ST_MATRIX_TMP) { 178 free (V2[0].buffer[0].header.buffer); 179 free (V2[0].buffer[0].matrix.buffer); 180 free (V2[0].buffer); 181 } 182 if (V3[0].type == ST_MATRIX_TMP) { 183 free (V3[0].buffer[0].header.buffer); 184 free (V3[0].buffer[0].matrix.buffer); 185 free (V3[0].buffer); 186 } 187 188 /* at the end, V1 and V2 are deleted only if they were temporary */ 189 190 clear_stack (V1); 191 clear_stack (V2); 192 clear_stack (V3); 193 return (TRUE); 194 195 } 196 197 // XXX we temporarily drop the concept of using one of the temporary input vectors for 198 // the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors 199 // as well as their temporary state 200 201 int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) { 202 203 int i, Nx; 204 char line[512]; // this is only used to report an error 205 206 // the vectors have to match in length 207 if (V1[0].vector[0].Nelements != V2[0].vector[0].Nelements) { 208 return (FALSE); 209 } 210 211 Nx = V1[0].vector[0].Nelements; 212 213 // create the output vector guaranteed to be temporary until the very end 214 OUT[0].vector = InitVector (); 215 OUT[0].type = ST_VECTOR_TMP; 27 216 28 217 // set up the possible operations : int OP int -> int, all else yield float … … 59 248 break; \ 60 249 } \ 61 if ((FTYPE == 'S') && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \250 if ((FTYPE == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \ 62 251 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT); \ 63 252 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 82 271 83 272 switch (op[0]) { 84 case '+': VV_FUNC('s', *M1 + *M2); 85 case '-': VV_FUNC('s', *M1 - *M2); 86 case '*': VV_FUNC('s', *M1 * *M2); 87 case '/': VV_FUNC('S', *M1 / (opihi_flt) *M2); 88 case '%': VV_FUNC('s', (long long)*M1 % (long long)*M2); 89 case '^': VV_FUNC('S', pow (*M1, *M2)); 90 case '@': VV_FUNC('S', DEG_RAD*atan2 (*M1, *M2)); 91 case 'D': VV_FUNC('s', MIN (*M1, *M2)); 92 case 'U': VV_FUNC('s', MAX (*M1, *M2)); 93 case '<': VV_FUNC('s', (*M1 < *M2) ? 1 : 0); 94 case '>': VV_FUNC('s', (*M1 > *M2) ? 1 : 0); 95 case '&': VV_FUNC('s', ((long long)*M1 & (long long)*M2)); 96 case '|': VV_FUNC('s', ((long long)*M1 | (long long)*M2)); 97 case 'E': VV_FUNC('s', (*M1 == *M2) ? 1 : 0); 98 case 'N': VV_FUNC('s', (*M1 != *M2) ? 1 : 0); 99 case 'L': VV_FUNC('s', (*M1 <= *M2) ? 1 : 0); 100 case 'G': VV_FUNC('s', (*M1 >= *M2) ? 1 : 0); 101 case 'A': VV_FUNC('s', (*M1 && *M2) ? 1 : 0); 102 case 'O': VV_FUNC('s', (*M1 || *M2) ? 1 : 0); 273 case '+': VV_FUNC(ST_SCALAR_INT, *M1 + *M2); 274 case '-': VV_FUNC(ST_SCALAR_INT, *M1 - *M2); 275 case '*': VV_FUNC(ST_SCALAR_INT, *M1 * *M2); 276 case '/': VV_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) *M2); 277 case '%': VV_FUNC(ST_SCALAR_INT, (long long)*M1 % (long long)*M2); 278 case '^': VV_FUNC(ST_SCALAR_FLT, pow (*M1, *M2)); 279 case '@': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2)); 280 case 'a': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2)); 281 case 'D': VV_FUNC(ST_SCALAR_INT, MIN (*M1, *M2)); 282 case 'U': VV_FUNC(ST_SCALAR_INT, MAX (*M1, *M2)); 283 case '<': VV_FUNC(ST_SCALAR_INT, (*M1 < *M2) ? 1 : 0); 284 case '>': VV_FUNC(ST_SCALAR_INT, (*M1 > *M2) ? 1 : 0); 285 case '&': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)*M2)); 286 case '|': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)*M2)); 287 case 'E': VV_FUNC(ST_SCALAR_INT, (*M1 == *M2) ? 1 : 0); 288 case 'N': VV_FUNC(ST_SCALAR_INT, (*M1 != *M2) ? 1 : 0); 289 case 'L': VV_FUNC(ST_SCALAR_INT, (*M1 <= *M2) ? 1 : 0); 290 case 'G': VV_FUNC(ST_SCALAR_INT, (*M1 >= *M2) ? 1 : 0); 291 case 'A': VV_FUNC(ST_SCALAR_INT, (*M1 && *M2) ? 1 : 0); 292 case 'O': VV_FUNC(ST_SCALAR_INT, (*M1 || *M2) ? 1 : 0); 103 293 default: 104 s printf (line, "error: op %c not defined!", op[0]);294 snprintf (line, 512, "error: op %c not defined!", op[0]); 105 295 push_error (line); 106 296 return (FALSE); … … 110 300 /** free up any temporary buffers: **/ 111 301 112 if (V1[0].type == 'v') {302 if (V1[0].type == ST_VECTOR_TMP) { 113 303 free (V1[0].vector[0].elements.Ptr); 114 304 free (V1[0].vector); 115 305 } 116 if (V2[0].type == 'v') {306 if (V2[0].type == ST_VECTOR_TMP) { 117 307 free (V2[0].vector[0].elements.Ptr); 118 308 free (V2[0].vector); … … 134 324 135 325 OUT[0].vector = InitVector (); 136 OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/326 OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/ 137 327 138 328 // set up the possible operations : int OP int -> int, all else yield float 139 329 // OP is the operation performed on *M1 and *M2 140 330 # define SV_FUNC(FTYPE,OP) { \ 141 if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) { \331 if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) { \ 142 332 CopyVector (OUT[0].vector, V2[0].vector); \ 143 333 opihi_flt M1 = V1[0].FltValue; \ … … 149 339 break; \ 150 340 } \ 151 if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) { \341 if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) { \ 152 342 MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT); \ 153 343 opihi_flt M1 = V1[0].FltValue; \ … … 159 349 break; \ 160 350 } \ 161 if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) { \351 if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) { \ 162 352 CopyVector (OUT[0].vector, V2[0].vector); \ 163 353 opihi_int M1 = V1[0].IntValue; \ … … 169 359 break; \ 170 360 } \ 171 if ((FTYPE == 'S') && (V1->type == 's') && (V2->vector->type != OPIHI_FLT)) { \361 if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \ 172 362 MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT); \ 173 363 opihi_int M1 = V1[0].IntValue; \ … … 179 369 break; \ 180 370 } \ 181 if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) { \371 if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \ 182 372 CopyVector (OUT[0].vector, V2[0].vector); \ 183 373 opihi_int M1 = V1[0].IntValue; \ … … 192 382 193 383 switch (op[0]) { 194 case '+': SV_FUNC('s', M1 + *M2); 195 case '-': SV_FUNC('s', M1 - *M2); 196 case '*': SV_FUNC('s', M1 * *M2); 197 case '/': SV_FUNC('S', M1 / (opihi_flt) *M2); 198 case '%': SV_FUNC('s', (long long) M1 % (long long) *M2); 199 case '^': SV_FUNC('S', pow (M1, *M2)); 200 case '@': SV_FUNC('S', DEG_RAD*atan2 (M1, *M2)); 201 case 'D': SV_FUNC('s', MIN (M1, *M2)); 202 case 'U': SV_FUNC('s', MAX (M1, *M2)); 203 case '<': SV_FUNC('s', (M1 < *M2) ? 1 : 0); 204 case '>': SV_FUNC('s', (M1 > *M2) ? 1 : 0); 205 case '&': SV_FUNC('s', ((long long)M1 & (long long)*M2)); 206 case '|': SV_FUNC('s', ((long long)M1 | (long long)*M2)); 207 case 'E': SV_FUNC('s', (M1 == *M2) ? 1 : 0); 208 case 'N': SV_FUNC('s', (M1 != *M2) ? 1 : 0); 209 case 'L': SV_FUNC('s', (M1 <= *M2) ? 1 : 0); 210 case 'G': SV_FUNC('s', (M1 >= *M2) ? 1 : 0); 211 case 'A': SV_FUNC('s', (M1 && *M2) ? 1 : 0); 212 case 'O': SV_FUNC('s', (M1 || *M2) ? 1 : 0); 384 case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2); 385 case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2); 386 case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2); 387 case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2); 388 case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2); 389 case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2)); 390 case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2)); 391 case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2)); 392 case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2)); 393 case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2)); 394 case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0); 395 case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0); 396 case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2)); 397 case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2)); 398 case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0); 399 case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0); 400 case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0); 401 case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0); 402 case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0); 403 case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0); 213 404 default: 214 s printf (line, "error: op %c not defined!", op[0]);405 snprintf (line, 512, "error: op %c not defined!", op[0]); 215 406 push_error (line); 216 407 return (FALSE); … … 219 410 220 411 /** free up any temporary buffers: **/ 221 if (V2[0].type == 'v') {412 if (V2[0].type == ST_VECTOR_TMP) { 222 413 free (V2[0].vector[0].elements.Ptr); 223 414 free (V2[0].vector); … … 240 431 241 432 OUT[0].vector = InitVector (); 242 OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/433 OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/ 243 434 244 435 // set up the possible operations : int OP int -> int, all else yield float 245 436 // OP is the operation performed on *M1 and *M2 246 437 # define VS_FUNC(FTYPE,OP) { \ 247 if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) { \438 if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) { \ 248 439 CopyVector (OUT[0].vector, V1[0].vector); \ 249 440 opihi_flt *M1 = V1[0].vector[0].elements.Flt; \ … … 255 446 break; \ 256 447 } \ 257 if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) { \448 if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) { \ 258 449 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT); \ 259 450 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 265 456 break; \ 266 457 } \ 267 if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) { \458 if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) { \ 268 459 CopyVector (OUT[0].vector, V1[0].vector); \ 269 460 opihi_flt *M1 = V1[0].vector[0].elements.Flt; \ … … 275 466 break; \ 276 467 } \ 277 if ((FTYPE == 'S') && (V2->type == 's') && (V1->vector->type != OPIHI_FLT)) { \468 if ((FTYPE == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \ 278 469 CopyVector (OUT[0].vector, V1[0].vector); \ 279 470 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 285 476 break; \ 286 477 } \ 287 if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) { \478 if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \ 288 479 CopyVector (OUT[0].vector, V1[0].vector); \ 289 480 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 298 489 299 490 switch (op[0]) { 300 case '+': VS_FUNC('s', *M1 + M2); 301 case '-': VS_FUNC('s', *M1 - M2); 302 case '*': VS_FUNC('s', *M1 * M2); 303 case '/': VS_FUNC('S', *M1 / (opihi_flt) M2); 304 case '%': VS_FUNC('s', (long long) *M1 % (long long) M2); 305 case '^': VS_FUNC('S', pow (*M1, M2)); 306 case '@': VS_FUNC('S', DEG_RAD*atan2 (*M1, M2)); 307 case 'D': VS_FUNC('s', MIN (*M1, M2)); 308 case 'U': VS_FUNC('s', MAX (*M1, M2)); 309 case '<': VS_FUNC('s', (*M1 < M2) ? 1 : 0); 310 case '>': VS_FUNC('s', (*M1 > M2) ? 1 : 0); 311 case '&': VS_FUNC('s', ((long long)*M1 & (long long)M2)); 312 case '|': VS_FUNC('s', ((long long)*M1 | (long long)M2)); 313 case 'E': VS_FUNC('s', (*M1 == M2) ? 1 : 0); 314 case 'N': VS_FUNC('s', (*M1 != M2) ? 1 : 0); 315 case 'L': VS_FUNC('s', (*M1 <= M2) ? 1 : 0); 316 case 'G': VS_FUNC('s', (*M1 >= M2) ? 1 : 0); 317 case 'A': VS_FUNC('s', (*M1 && M2) ? 1 : 0); 318 case 'O': VS_FUNC('s', (*M1 || M2) ? 1 : 0); 491 case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2); 492 case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2); 493 case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2); 494 case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2); 495 case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2); 496 case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2)); 497 case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2)); 498 case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2)); 499 case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2)); 500 case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2)); 501 case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0); 502 case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0); 503 case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2)); 504 case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2)); 505 case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0); 506 case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0); 507 case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0); 508 case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0); 509 case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0); 510 case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0); 319 511 default: 320 s printf (line, "error: op %c not defined!", op[0]);512 snprintf (line, 512, "error: op %c not defined!", op[0]); 321 513 push_error (line); 322 514 return (FALSE); … … 326 518 /** free up any temporary buffers: **/ 327 519 328 if (V1[0].type == 'v') {520 if (V1[0].type == ST_VECTOR_TMP) { 329 521 free (V1[0].vector[0].elements.Ptr); 330 522 free (V1[0].vector); … … 353 545 354 546 /* if possible, use V1 as temp buffer, otherwise create new one */ 355 if (V1[0].type == 'm') {547 if (V1[0].type == ST_MATRIX_TMP) { 356 548 OUT[0].buffer = V1[0].buffer; 357 V1[0].type = 'M'; /* prevent it from being freed below */549 V1[0].type = ST_MATRIX; /* prevent it from being freed below */ 358 550 } else { 359 551 /* do buffer.matrix.buffer and buffer.header.buffer get correctly zeroed? */ … … 361 553 CopyBuffer (OUT[0].buffer, V1[0].buffer); 362 554 } 363 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/555 OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/ 364 556 365 557 float *M1 = (float *) V1[0].buffer[0].matrix.buffer; … … 395 587 case '^': MV_FUNC(pow (*M1, *M2)); 396 588 case '@': MV_FUNC(DEG_RAD*atan2 (*M1, *M2)); 589 case 'a': MV_FUNC(DEG_RAD*atan2 (*M1, *M2)); 397 590 case 'D': MV_FUNC(MIN (*M1, *M2)); 398 591 case 'U': MV_FUNC(MAX (*M1, *M2)); … … 408 601 case 'O': MV_FUNC((*M1 || *M2) ? 1 : 0); 409 602 default: 410 s printf (line, "error: op %c not defined!", op[0]);603 snprintf (line, 512, "error: op %c not defined!", op[0]); 411 604 push_error (line); 412 605 return (FALSE); … … 416 609 /** free up any temporary buffers: **/ 417 610 418 if (V1[0].type == 'm') {611 if (V1[0].type == ST_MATRIX_TMP) { 419 612 free (V1[0].buffer[0].header.buffer); 420 613 free (V1[0].buffer[0].matrix.buffer); 421 614 free (V1[0].buffer); 422 615 } 423 if (V2[0].type == 'v') {616 if (V2[0].type == ST_VECTOR_TMP) { 424 617 free (V2[0].vector[0].elements.Ptr); 425 618 free (V2[0].vector); … … 446 639 447 640 /* if possible, use V2 as temp buffer, otherwise create new one */ 448 if (V2[0].type == 'm') {641 if (V2[0].type == ST_MATRIX_TMP) { 449 642 OUT[0].buffer = V2[0].buffer; 450 V2[0].type = 'M'; /* prevent it from being freed below */643 V2[0].type = ST_MATRIX; /* prevent it from being freed below */ 451 644 } else { /* no spare temp buffer */ 452 645 OUT[0].buffer = InitBuffer (); 453 646 CopyBuffer (OUT[0].buffer, V2[0].buffer); 454 647 } 455 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/648 OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/ 456 649 457 650 float *M2 = (float *) V2[0].buffer[0].matrix.buffer; … … 487 680 case '^': VM_FUNC(pow (*M1, *M2)); 488 681 case '@': VM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 682 case 'a': VM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 489 683 case 'D': VM_FUNC(MIN (*M1, *M2)); 490 684 case 'U': VM_FUNC(MAX (*M1, *M2)); … … 500 694 case 'O': VM_FUNC((*M1 || *M2) ? 1 : 0); 501 695 default: 502 s printf (line, "error: op %c not defined!", op[0]);696 snprintf (line, 512, "error: op %c not defined!", op[0]); 503 697 push_error (line); 504 698 return (FALSE); … … 508 702 /** free up any temporary buffers: **/ 509 703 510 if (V1[0].type == 'v') {704 if (V1[0].type == ST_VECTOR_TMP) { 511 705 free (V1[0].vector[0].elements.Ptr); 512 706 free (V1[0].vector); 513 707 } 514 if (V2[0].type == 'm') {708 if (V2[0].type == ST_MATRIX_TMP) { 515 709 free (V2[0].buffer[0].header.buffer); 516 710 free (V2[0].buffer[0].matrix.buffer); … … 535 729 Ny = V1[0].buffer[0].matrix.Naxis[1]; 536 730 537 if (V1[0].type == 'm') { /** use V1 as temp buffer **/731 if (V1[0].type == ST_MATRIX_TMP) { /** use V1 as temp buffer **/ 538 732 OUT[0].buffer = V1[0].buffer; 539 V1[0].type = 'M'; /* prevent it from being freed below */733 V1[0].type = ST_MATRIX; /* prevent it from being freed below */ 540 734 } else { 541 if (V2[0].type == 'm') { /** use V2 as temp buffer, but header of V1 **/735 if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/ 542 736 OUT[0].buffer = V2[0].buffer; 543 V2[0].type = 'M'; /* prevent it from being freed below */737 V2[0].type = ST_MATRIX; /* prevent it from being freed below */ 544 738 } else { /* no spare temp buffer */ 545 739 OUT[0].buffer = InitBuffer (); … … 547 741 } 548 742 } 549 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/743 OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/ 550 744 551 745 M1 = (float *)V1[0].buffer[0].matrix.buffer; … … 567 761 case '^': MM_FUNC(pow (*M1, *M2)); 568 762 case '@': MM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 763 case 'a': MM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 569 764 case 'D': MM_FUNC(MIN (*M1, *M2)); 570 765 case 'U': MM_FUNC(MAX (*M1, *M2)); … … 580 775 case 'O': MM_FUNC((*M1 || *M2) ? 1 : 0); 581 776 default: 582 s printf (line, "error: op %c not defined!", op[0]);777 snprintf (line, 512, "error: op %c not defined!", op[0]); 583 778 push_error (line); 584 779 return (FALSE); … … 588 783 /** free up any temporary buffers: **/ 589 784 590 if (V1[0].type == 'm') {785 if (V1[0].type == ST_MATRIX_TMP) { 591 786 free (V1[0].buffer[0].header.buffer); 592 787 free (V1[0].buffer[0].matrix.buffer); 593 788 free (V1[0].buffer); 594 789 } 595 if (V2[0].type == 'm') {790 if (V2[0].type == ST_MATRIX_TMP) { 596 791 free (V2[0].buffer[0].header.buffer); 597 792 free (V2[0].buffer[0].matrix.buffer); … … 615 810 616 811 /* if possible, use V1 as temp buffer, otherwise create new one */ 617 if (V1[0].type == 'm') {812 if (V1[0].type == ST_MATRIX_TMP) { 618 813 OUT[0].buffer = V1[0].buffer; 619 V1[0].type = 'M'; /* prevent it from being freed below */814 V1[0].type = ST_MATRIX; /* prevent it from being freed below */ 620 815 } else { 621 816 OUT[0].buffer = InitBuffer (); 622 817 CopyBuffer (OUT[0].buffer, V1[0].buffer); 623 818 } 624 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/819 OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/ 625 820 626 821 float *M1 = (float *)V1[0].buffer[0].matrix.buffer; … … 628 823 629 824 # define MS_FUNC(OP) { \ 630 if (V2->type == 'S') { \825 if (V2->type == ST_SCALAR_FLT) { \ 631 826 opihi_flt M2 = V2[0].FltValue; \ 632 827 for (i = 0; i < Nx*Ny; i++, out++, M1++) { \ … … 635 830 break; \ 636 831 } \ 637 if (V2->type == 's') { \832 if (V2->type == ST_SCALAR_INT) { \ 638 833 opihi_int M2 = V2[0].IntValue; \ 639 834 for (i = 0; i < Nx*Ny; i++, out++, M1++) { \ … … 652 847 case '^': MS_FUNC(pow (*M1, M2)); 653 848 case '@': MS_FUNC(DEG_RAD*atan2 (*M1, M2)); 849 case 'a': MS_FUNC(DEG_RAD*atan2 (*M1, M2)); 654 850 case 'D': MS_FUNC(MIN (*M1, M2)); 655 851 case 'U': MS_FUNC(MAX (*M1, M2)); … … 665 861 case 'O': MS_FUNC((*M1 || M2) ? 1 : 0); 666 862 default: 667 s printf (line, "error: op %c not defined!", op[0]);863 snprintf (line, 512, "error: op %c not defined!", op[0]); 668 864 push_error (line); 669 865 return (FALSE); … … 671 867 # undef MS_FUNC 672 868 673 if (V1[0].type == 'm') {869 if (V1[0].type == ST_MATRIX_TMP) { 674 870 free (V1[0].buffer[0].header.buffer); 675 871 free (V1[0].buffer[0].matrix.buffer); … … 691 887 Ny = V2[0].buffer[0].matrix.Naxis[1]; 692 888 693 if (V2[0].type == 'm') { /* V2[0] is NOT temporary, we can't use it for storage */889 if (V2[0].type == ST_MATRIX_TMP) { /* V2[0] is NOT temporary, we can't use it for storage */ 694 890 OUT[0].buffer = V2[0].buffer; 695 V2[0].type = 'M'; /* prevent it from being freed below */891 V2[0].type = ST_MATRIX; /* prevent it from being freed below */ 696 892 } else { 697 893 OUT[0].buffer = InitBuffer (); 698 894 CopyBuffer (OUT[0].buffer, V2[0].buffer); 699 895 } 700 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/896 OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/ 701 897 702 898 float *M2 = (float *)V2[0].buffer[0].matrix.buffer; … … 704 900 705 901 # define SM_FUNC(OP) { \ 706 if (V1->type == 'S') { \902 if (V1->type == ST_SCALAR_FLT) { \ 707 903 opihi_flt M1 = V1[0].FltValue; \ 708 904 for (i = 0; i < Nx*Ny; i++, out++, M2++) { \ … … 711 907 break; \ 712 908 } \ 713 if (V1->type == 's') { \909 if (V1->type == ST_SCALAR_INT) { \ 714 910 opihi_int M1 = V1[0].IntValue; \ 715 911 for (i = 0; i < Nx*Ny; i++, out++, M2++) { \ … … 728 924 case '^': SM_FUNC(pow (M1, *M2)); 729 925 case '@': SM_FUNC(DEG_RAD*atan2 (M1, *M2)); 926 case 'a': SM_FUNC(DEG_RAD*atan2 (M1, *M2)); 730 927 case 'D': SM_FUNC(MIN (M1, *M2)); 731 928 case 'U': SM_FUNC(MAX (M1, *M2)); … … 741 938 case 'O': SM_FUNC((M1 || *M2) ? 1 : 0); 742 939 default: 743 s printf (line, "error: op %c not defined!", op[0]);940 snprintf (line, 512, "error: op %c not defined!", op[0]); 744 941 push_error (line); 745 942 return (FALSE); … … 747 944 # undef SM_FUNC 748 945 749 if (V2[0].type == 'm') {946 if (V2[0].type == ST_MATRIX_TMP) { 750 947 free (V2[0].buffer[0].header.buffer); 751 948 free (V2[0].buffer[0].matrix.buffer); … … 764 961 765 962 # define SS_FUNC(FTYPE,OP) { \ 766 if ((V1->type == 'S') && (V2->type == 'S')) { \963 if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) { \ 767 964 opihi_flt M1 = V1[0].FltValue; \ 768 965 opihi_flt M2 = V2[0].FltValue; \ 769 OUT[0].type = 'S'; \966 OUT[0].type = ST_SCALAR_FLT; \ 770 967 OUT[0].FltValue = OP; \ 771 968 break; \ 772 969 } \ 773 if ((V1->type == 'S') && (V2->type == 's')) { \970 if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) { \ 774 971 opihi_flt M1 = V1[0].FltValue; \ 775 972 opihi_int M2 = V2[0].IntValue; \ 776 OUT[0].type = 'S'; \973 OUT[0].type = ST_SCALAR_FLT; \ 777 974 OUT[0].FltValue = OP; \ 778 975 break; \ 779 976 } \ 780 if ((V1->type == 's') && (V2->type == 'S')) { \977 if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) { \ 781 978 opihi_int M1 = V1[0].IntValue; \ 782 979 opihi_flt M2 = V2[0].FltValue; \ 783 OUT[0].type = 'S'; \980 OUT[0].type = ST_SCALAR_FLT; \ 784 981 OUT[0].FltValue = OP; \ 785 982 break; \ 786 983 } \ 787 if ((FTYPE == 'S') && (V1->type == 's') && (V2->type == 's')) { \984 if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \ 788 985 opihi_int M1 = V1[0].IntValue; \ 789 986 opihi_int M2 = V2[0].IntValue; \ 790 OUT[0].type = 'S'; \987 OUT[0].type = ST_SCALAR_FLT; \ 791 988 OUT[0].FltValue = OP; \ 792 989 break; \ 793 990 } \ 794 if ((V1->type == 's') && (V2->type == 's')) { \991 if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \ 795 992 opihi_int M1 = V1[0].IntValue; \ 796 993 opihi_int M2 = V2[0].IntValue; \ 797 OUT[0].type = 's'; \994 OUT[0].type = ST_SCALAR_INT; \ 798 995 OUT[0].IntValue = OP; \ 799 996 break; \ … … 802 999 803 1000 switch (op[0]) { 804 case '+': SS_FUNC('s', M1 + M2); 805 case '-': SS_FUNC('s', M1 - M2); 806 case '*': SS_FUNC('s', M1 * M2); 807 case '/': SS_FUNC('S', M1 / (opihi_flt) M2); 808 case '%': SS_FUNC('s', (long long) M1 % (long long) M2); 809 case '^': SS_FUNC('S', pow (M1, M2)); 810 case '@': SS_FUNC('S', DEG_RAD*atan2 (M1, M2)); 811 case 'D': SS_FUNC('s', MIN (M1, M2)); 812 case 'U': SS_FUNC('s', MAX (M1, M2)); 813 case '<': SS_FUNC('s', (M1 < M2) ? 1 : 0); 814 case '>': SS_FUNC('s', (M1 > M2) ? 1 : 0); 815 case '&': SS_FUNC('s', ((long long)M1 & (long long)M2)); 816 case '|': SS_FUNC('s', ((long long)M1 | (long long)M2)); 817 case 'E': SS_FUNC('s', (M1 == M2) ? 1 : 0); 818 case 'N': SS_FUNC('s', (M1 != M2) ? 1 : 0); 819 case 'L': SS_FUNC('s', (M1 <= M2) ? 1 : 0); 820 case 'G': SS_FUNC('s', (M1 >= M2) ? 1 : 0); 821 case 'A': SS_FUNC('s', (M1 && M2) ? 1 : 0); 822 case 'O': SS_FUNC('s', (M1 || M2) ? 1 : 0); 1001 case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2); 1002 case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2); 1003 case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2); 1004 case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2); 1005 case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2); 1006 case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2)); 1007 case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2)); 1008 case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2)); 1009 case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2)); 1010 case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2)); 1011 case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0); 1012 case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0); 1013 case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2)); 1014 case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2)); 1015 case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0); 1016 case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0); 1017 case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0); 1018 case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0); 1019 case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0); 1020 case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0); 823 1021 default: 824 s printf (line, "error: op %c not defined!", op[0]);1022 snprintf (line, 512, "error: op %c not defined!", op[0]); 825 1023 push_error (line); 826 1024 return (FALSE); … … 844 1042 845 1043 if ((op[0] != 'N') && (op[0] != 'E')) { 846 s printf (line, "error: op %c not defined for string operations!", op[0]);1044 snprintf (line, 512, "error: op %c not defined for string operations!", op[0]); 847 1045 push_error (line); 848 1046 return (FALSE); … … 853 1051 thus: string == number -> false */ 854 1052 855 if ( !strncasecmp (&V1[0].type, "S", 1)) {1053 if (V1[0].type == ST_SCALAR_INT) { 856 1054 value = (op[0] == 'N'); 857 1055 goto escape; 858 1056 } 859 if (!strncasecmp (&V2[0].type, "S", 1)) { 1057 if (V1[0].type == ST_SCALAR_FLT) { 1058 value = (op[0] == 'N'); 1059 goto escape; 1060 } 1061 if (V2[0].type == ST_SCALAR_INT) { 1062 value = (op[0] == 'N'); 1063 goto escape; 1064 } 1065 if (V2[0].type == ST_SCALAR_FLT) { 860 1066 value = (op[0] == 'N'); 861 1067 goto escape; … … 870 1076 break; 871 1077 default: 872 s printf (line, "error: op %c not defined for string operations!", op[0]);1078 snprintf (line, 512, "error: op %c not defined for string operations!", op[0]); 873 1079 push_error (line); 874 1080 return (FALSE); … … 877 1083 escape: 878 1084 OUT[0].FltValue = value; 879 OUT[0].type = 'S';1085 OUT[0].type = ST_SCALAR_FLT; 880 1086 881 1087 clear_stack (V1); … … 891 1097 892 1098 # define S_FUNC(OP,FTYPE) { \ 893 if (V1->type == 'S') { \1099 if (V1->type == ST_SCALAR_FLT) { \ 894 1100 opihi_flt M1 = V1[0].FltValue; \ 895 OUT[0].type = 'S'; \1101 OUT[0].type = ST_SCALAR_FLT; \ 896 1102 OUT[0].FltValue = OP; \ 897 1103 clear_stack (V1); \ 898 1104 return (TRUE); \ 899 1105 } \ 900 if ((FTYPE == 'S') && (V1->type == 's')) { \1106 if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) { \ 901 1107 opihi_int M1 = V1[0].IntValue; \ 902 OUT[0].type = 'S'; \1108 OUT[0].type = ST_SCALAR_FLT; \ 903 1109 OUT[0].FltValue = OP; \ 904 1110 clear_stack (V1); \ 905 1111 return (TRUE); \ 906 1112 } \ 907 if ((FTYPE == 's') && (V1->type == 's')) { \1113 if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) { \ 908 1114 opihi_int M1 = V1[0].IntValue; \ 909 OUT[0].type = 's'; \1115 OUT[0].type = ST_SCALAR_INT; \ 910 1116 OUT[0].IntValue = OP; \ 911 1117 clear_stack (V1); \ … … 914 1120 } 915 1121 916 if (!strcmp (op, "=")) S_FUNC(M1, 's');917 if (!strcmp (op, "abs")) S_FUNC(fabs(M1), 's');918 if (!strcmp (op, "int")) S_FUNC((long long)(M1), 's');919 if (!strcmp (op, "exp")) S_FUNC(exp (M1), 'S');920 if (!strcmp (op, "ten")) S_FUNC(pow (10.0,M1), 'S');921 if (!strcmp (op, "log")) S_FUNC(log10 (M1), 'S');922 if (!strcmp (op, "ln")) S_FUNC(log (M1), 'S');923 if (!strcmp (op, "sqrt")) S_FUNC(sqrt (M1), 'S');924 if (!strcmp (op, "erf")) S_FUNC(erf (M1), 'S');925 if (!strcmp (op, "sinh")) S_FUNC(sinh (M1), 'S');926 if (!strcmp (op, "cosh")) S_FUNC(cosh (M1), 'S');927 if (!strcmp (op, "asinh")) S_FUNC(asinh (M1), 'S');928 if (!strcmp (op, "acosh")) S_FUNC(acosh (M1), 'S');929 if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), 'S');930 if (!strcmp (op, "sin")) S_FUNC(sin (M1), 'S');931 if (!strcmp (op, "cos")) S_FUNC(cos (M1), 'S');932 if (!strcmp (op, "tan")) S_FUNC(tan (M1), 'S');933 if (!strcmp (op, "dsin")) S_FUNC(sin (M1*RAD_DEG), 'S');934 if (!strcmp (op, "dcos")) S_FUNC(cos (M1*RAD_DEG), 'S');935 if (!strcmp (op, "dtan")) S_FUNC(tan (M1*RAD_DEG), 'S');936 if (!strcmp (op, "asin")) S_FUNC(asin (M1), 'S');937 if (!strcmp (op, "acos")) S_FUNC(acos (M1), 'S');938 if (!strcmp (op, "atan")) S_FUNC(atan (M1), 'S');939 if (!strcmp (op, "dasin")) S_FUNC(asin (M1)*DEG_RAD, 'S');940 if (!strcmp (op, "dacos")) S_FUNC(acos (M1)*DEG_RAD, 'S');941 if (!strcmp (op, "datan")) S_FUNC(atan (M1)*DEG_RAD, 'S');942 if (!strcmp (op, "rnd")) S_FUNC(M1*0.0 + drand48(), 'S');943 if (!strcmp (op, "not")) S_FUNC(!(M1), 's');944 if (!strcmp (op, "--")) S_FUNC(-1*M1, 's'); // NOTE: opihi_int is signed,945 if (!strcmp (op, "isinf")) S_FUNC(!finite(M1), 'S'); // XXX modify in future946 if (!strcmp (op, "isnan")) S_FUNC(isnan(M1), 'S'); // XXX modify in future1122 if (!strcmp (op, "=")) S_FUNC(M1, ST_SCALAR_INT); 1123 if (!strcmp (op, "abs")) S_FUNC(fabs(M1), ST_SCALAR_INT); 1124 if (!strcmp (op, "int")) S_FUNC((long long)(M1), ST_SCALAR_INT); 1125 if (!strcmp (op, "exp")) S_FUNC(exp (M1), ST_SCALAR_FLT); 1126 if (!strcmp (op, "ten")) S_FUNC(pow (10.0,M1), ST_SCALAR_FLT); 1127 if (!strcmp (op, "log")) S_FUNC(log10 (M1), ST_SCALAR_FLT); 1128 if (!strcmp (op, "ln")) S_FUNC(log (M1), ST_SCALAR_FLT); 1129 if (!strcmp (op, "sqrt")) S_FUNC(sqrt (M1), ST_SCALAR_FLT); 1130 if (!strcmp (op, "erf")) S_FUNC(erf (M1), ST_SCALAR_FLT); 1131 if (!strcmp (op, "sinh")) S_FUNC(sinh (M1), ST_SCALAR_FLT); 1132 if (!strcmp (op, "cosh")) S_FUNC(cosh (M1), ST_SCALAR_FLT); 1133 if (!strcmp (op, "asinh")) S_FUNC(asinh (M1), ST_SCALAR_FLT); 1134 if (!strcmp (op, "acosh")) S_FUNC(acosh (M1), ST_SCALAR_FLT); 1135 if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT); 1136 if (!strcmp (op, "sin")) S_FUNC(sin (M1), ST_SCALAR_FLT); 1137 if (!strcmp (op, "cos")) S_FUNC(cos (M1), ST_SCALAR_FLT); 1138 if (!strcmp (op, "tan")) S_FUNC(tan (M1), ST_SCALAR_FLT); 1139 if (!strcmp (op, "dsin")) S_FUNC(sin (M1*RAD_DEG), ST_SCALAR_FLT); 1140 if (!strcmp (op, "dcos")) S_FUNC(cos (M1*RAD_DEG), ST_SCALAR_FLT); 1141 if (!strcmp (op, "dtan")) S_FUNC(tan (M1*RAD_DEG), ST_SCALAR_FLT); 1142 if (!strcmp (op, "asin")) S_FUNC(asin (M1), ST_SCALAR_FLT); 1143 if (!strcmp (op, "acos")) S_FUNC(acos (M1), ST_SCALAR_FLT); 1144 if (!strcmp (op, "atan")) S_FUNC(atan (M1), ST_SCALAR_FLT); 1145 if (!strcmp (op, "dasin")) S_FUNC(asin (M1)*DEG_RAD, ST_SCALAR_FLT); 1146 if (!strcmp (op, "dacos")) S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT); 1147 if (!strcmp (op, "datan")) S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT); 1148 if (!strcmp (op, "rnd")) S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT); 1149 if (!strcmp (op, "not")) S_FUNC(!(M1), ST_SCALAR_INT); 1150 if (!strcmp (op, "--")) S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed, 1151 if (!strcmp (op, "isinf")) S_FUNC(!finite(M1), ST_SCALAR_FLT); // XXX modify in future 1152 if (!strcmp (op, "isnan")) S_FUNC(isnan(M1), ST_SCALAR_FLT); // XXX modify in future 947 1153 948 1154 # undef S_FUNC 949 1155 950 1156 clear_stack (V1); 951 s printf (line, "error: op %s not defined!", op);1157 snprintf (line, 512, "error: op %s not defined!", op); 952 1158 push_error (line); 953 1159 return (FALSE); … … 962 1168 963 1169 OUT[0].vector = InitVector (); 964 OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/1170 OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/ 965 1171 966 1172 # define V_FUNC(OP,FTYPE) { \ … … 974 1180 goto escape; \ 975 1181 } \ 976 if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) { \1182 if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) { \ 977 1183 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT); \ 978 1184 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 983 1189 goto escape; \ 984 1190 } \ 985 if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) { \1191 if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) { \ 986 1192 CopyVector (OUT[0].vector, V1[0].vector); \ 987 1193 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 993 1199 } } 994 1200 995 if (!strcmp (op, "=")) V_FUNC(*M1, 's');996 if (!strcmp (op, "abs")) V_FUNC(fabs(*M1), 's');997 if (!strcmp (op, "int")) V_FUNC((long long)(*M1), 's');998 if (!strcmp (op, "exp")) V_FUNC(exp(*M1), 'S');999 if (!strcmp (op, "ten")) V_FUNC(pow(10.0,*M1), 'S');1000 if (!strcmp (op, "log")) V_FUNC(log10(*M1), 'S');1001 if (!strcmp (op, "ln")) V_FUNC(log(*M1), 'S');1002 if (!strcmp (op, "sqrt")) V_FUNC(sqrt(*M1), 'S');1003 if (!strcmp (op, "erf")) V_FUNC(erf(*M1), 'S');1004 if (!strcmp (op, "sinh")) V_FUNC(sinh(*M1), 'S');1005 if (!strcmp (op, "cosh")) V_FUNC(cosh(*M1), 'S');1006 if (!strcmp (op, "asinh")) V_FUNC(asinh(*M1), 'S');1007 if (!strcmp (op, "acosh")) V_FUNC(acosh(*M1), 'S');1008 if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), 'S');1009 if (!strcmp (op, "sin")) V_FUNC(sin(*M1), 'S');1010 if (!strcmp (op, "cos")) V_FUNC(cos(*M1), 'S');1011 if (!strcmp (op, "tan")) V_FUNC(tan(*M1), 'S');1012 if (!strcmp (op, "dsin")) V_FUNC(sin(*M1*RAD_DEG), 'S');1013 if (!strcmp (op, "dcos")) V_FUNC(cos(*M1*RAD_DEG), 'S');1014 if (!strcmp (op, "dtan")) V_FUNC(tan(*M1*RAD_DEG), 'S');1015 if (!strcmp (op, "asin")) V_FUNC(asin(*M1), 'S');1016 if (!strcmp (op, "acos")) V_FUNC(acos(*M1), 'S');1017 if (!strcmp (op, "atan")) V_FUNC(atan(*M1), 'S');1018 if (!strcmp (op, "dasin")) V_FUNC(asin(*M1)*DEG_RAD, 'S');1019 if (!strcmp (op, "dacos")) V_FUNC(acos(*M1)*DEG_RAD, 'S');1020 if (!strcmp (op, "datan")) V_FUNC(atan(*M1)*DEG_RAD, 'S');1021 if (!strcmp (op, "rnd")) V_FUNC(drand48(), 'S');1022 if (!strcmp (op, "ramp")) V_FUNC(i, 's');1023 if (!strcmp (op, "zero")) V_FUNC(0, 's');1024 if (!strcmp (op, "not")) V_FUNC(!(*M1), 's');1025 if (!strcmp (op, "--")) V_FUNC(-1*(*M1), 's'); // NOTE: opihi_int is signed1026 if (!strcmp (op, "isinf")) V_FUNC(!finite(*M1), 'S');1027 if (!strcmp (op, "isnan")) V_FUNC(isnan(*M1), 'S');1028 if (!strcmp (op, "xramp")) V_FUNC(i, 's');1029 if (!strcmp (op, "yramp")) V_FUNC(0, 's');1201 if (!strcmp (op, "=")) V_FUNC(*M1, ST_SCALAR_INT); 1202 if (!strcmp (op, "abs")) V_FUNC(fabs(*M1), ST_SCALAR_INT); 1203 if (!strcmp (op, "int")) V_FUNC((long long)(*M1), ST_SCALAR_INT); 1204 if (!strcmp (op, "exp")) V_FUNC(exp(*M1), ST_SCALAR_FLT); 1205 if (!strcmp (op, "ten")) V_FUNC(pow(10.0,*M1), ST_SCALAR_FLT); 1206 if (!strcmp (op, "log")) V_FUNC(log10(*M1), ST_SCALAR_FLT); 1207 if (!strcmp (op, "ln")) V_FUNC(log(*M1), ST_SCALAR_FLT); 1208 if (!strcmp (op, "sqrt")) V_FUNC(sqrt(*M1), ST_SCALAR_FLT); 1209 if (!strcmp (op, "erf")) V_FUNC(erf(*M1), ST_SCALAR_FLT); 1210 if (!strcmp (op, "sinh")) V_FUNC(sinh(*M1), ST_SCALAR_FLT); 1211 if (!strcmp (op, "cosh")) V_FUNC(cosh(*M1), ST_SCALAR_FLT); 1212 if (!strcmp (op, "asinh")) V_FUNC(asinh(*M1), ST_SCALAR_FLT); 1213 if (!strcmp (op, "acosh")) V_FUNC(acosh(*M1), ST_SCALAR_FLT); 1214 if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), ST_SCALAR_FLT); 1215 if (!strcmp (op, "sin")) V_FUNC(sin(*M1), ST_SCALAR_FLT); 1216 if (!strcmp (op, "cos")) V_FUNC(cos(*M1), ST_SCALAR_FLT); 1217 if (!strcmp (op, "tan")) V_FUNC(tan(*M1), ST_SCALAR_FLT); 1218 if (!strcmp (op, "dsin")) V_FUNC(sin(*M1*RAD_DEG), ST_SCALAR_FLT); 1219 if (!strcmp (op, "dcos")) V_FUNC(cos(*M1*RAD_DEG), ST_SCALAR_FLT); 1220 if (!strcmp (op, "dtan")) V_FUNC(tan(*M1*RAD_DEG), ST_SCALAR_FLT); 1221 if (!strcmp (op, "asin")) V_FUNC(asin(*M1), ST_SCALAR_FLT); 1222 if (!strcmp (op, "acos")) V_FUNC(acos(*M1), ST_SCALAR_FLT); 1223 if (!strcmp (op, "atan")) V_FUNC(atan(*M1), ST_SCALAR_FLT); 1224 if (!strcmp (op, "dasin")) V_FUNC(asin(*M1)*DEG_RAD, ST_SCALAR_FLT); 1225 if (!strcmp (op, "dacos")) V_FUNC(acos(*M1)*DEG_RAD, ST_SCALAR_FLT); 1226 if (!strcmp (op, "datan")) V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT); 1227 if (!strcmp (op, "rnd")) V_FUNC(drand48(), ST_SCALAR_FLT); 1228 if (!strcmp (op, "ramp")) V_FUNC(i, ST_SCALAR_INT); 1229 if (!strcmp (op, "zero")) V_FUNC(0, ST_SCALAR_INT); 1230 if (!strcmp (op, "not")) V_FUNC(!(*M1), ST_SCALAR_INT); 1231 if (!strcmp (op, "--")) V_FUNC(-1*(*M1), ST_SCALAR_INT); // NOTE: opihi_int is signed 1232 if (!strcmp (op, "isinf")) V_FUNC(!finite(*M1), ST_SCALAR_FLT); 1233 if (!strcmp (op, "isnan")) V_FUNC(isnan(*M1), ST_SCALAR_FLT); 1234 if (!strcmp (op, "xramp")) V_FUNC(i, ST_SCALAR_INT); 1235 if (!strcmp (op, "yramp")) V_FUNC(0, ST_SCALAR_INT); 1030 1236 /* xramp and yramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */ 1031 1237 … … 1034 1240 escape: 1035 1241 1036 if (V1[0].type == 'v') {1242 if (V1[0].type == ST_VECTOR_TMP) { 1037 1243 free (V1[0].vector[0].elements.Ptr); 1038 1244 free (V1[0].vector); … … 1053 1259 Ny = V1[0].buffer[0].matrix.Naxis[1]; 1054 1260 1055 if (V1[0].type == 'm') {1261 if (V1[0].type == ST_MATRIX_TMP) { 1056 1262 OUT[0].buffer = V1[0].buffer; 1057 V1[0].type = 'M'; /* prevent it from being freed below */1263 V1[0].type = ST_MATRIX; /* prevent it from being freed below */ 1058 1264 } else { 1059 1265 OUT[0].buffer = InitBuffer (); 1060 1266 CopyBuffer (OUT[0].buffer, V1[0].buffer); 1061 1267 } 1062 OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/1268 OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/ 1063 1269 M1 = (float *) V1[0].buffer[0].matrix.buffer; 1064 1270 out = (float *)OUT[0].buffer[0].matrix.buffer; … … 1116 1322 } 1117 1323 1118 if (V1[0].type == 'm') {1324 if (V1[0].type == ST_MATRIX_TMP) { 1119 1325 free (V1[0].buffer[0].header.buffer); 1120 1326 free (V1[0].buffer[0].matrix.buffer);
Note:
See TracChangeset
for help on using the changeset viewer.
