Changeset 38441 for trunk/Ohana/src/opihi/lib.shell/stack_math.c
- Timestamp:
- Jun 12, 2015, 6:18:23 PM (11 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/opihi/lib.shell/stack_math.c (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/ohana.20150429 merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r38062 r38441 12 12 // set up the possible operations : int OP int -> int, all else yield float 13 13 // OP is the operation performed on *M1 and *M2 14 # define SSS_FUNC(OP) { \14 # define SSS_FUNC(OP) { \ 15 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; \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 21 break; \ 22 22 } \ 23 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; \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 29 break; \ 30 30 } \ … … 32 32 33 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 }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 40 # undef SSS_FUNC 41 41 … … 68 68 // set up the possible operations : int OP int -> int, all else yield float 69 69 // OP is the operation performed on *M1 and *M2 70 # define VVV_FUNC(OP) { \70 # define VVV_FUNC(OP) { \ 71 71 if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \ 72 72 CopyVector (OUT[0].vector, V1[0].vector); \ … … 394 394 // OP is the operation performed on *M1 and *M2 395 395 # define SV_FUNC(FTYPE,OP) { \ 396 if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) { \396 if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) { \ 397 397 CopyVector (OUT[0].vector, V2[0].vector); \ 398 398 opihi_flt M1 = V1[0].FltValue; \ … … 404 404 break; \ 405 405 } \ 406 if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) { \406 if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) { \ 407 407 MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT); \ 408 408 opihi_flt M1 = V1[0].FltValue; \ … … 414 414 break; \ 415 415 } \ 416 if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) { \416 if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) { \ 417 417 CopyVector (OUT[0].vector, V2[0].vector); \ 418 418 opihi_int M1 = V1[0].IntValue; \ … … 434 434 break; \ 435 435 } \ 436 if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \436 if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \ 437 437 CopyVector (OUT[0].vector, V2[0].vector); \ 438 438 opihi_int M1 = V1[0].IntValue; \ … … 447 447 448 448 switch (op[0]) { 449 case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);450 case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);451 case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);452 case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);453 case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);454 case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));455 case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));456 case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));457 case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));458 case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));459 case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);460 case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);461 case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));462 case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));463 case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);464 case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);465 case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);466 case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);467 case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);468 case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);469 default:470 snprintf (line, 512, "error: op %c not defined!", op[0]);471 push_error (line);472 return (FALSE);473 }449 case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2); 450 case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2); 451 case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2); 452 case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2); 453 case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2); 454 case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2)); 455 case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2)); 456 case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2)); 457 case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2)); 458 case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2)); 459 case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0); 460 case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0); 461 case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2)); 462 case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2)); 463 case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0); 464 case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0); 465 case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0); 466 case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0); 467 case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0); 468 case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0); 469 default: 470 snprintf (line, 512, "error: op %c not defined!", op[0]); 471 push_error (line); 472 return (FALSE); 473 } 474 474 # undef SV_FUNC 475 475 476 476 /** free up any temporary buffers: **/ 477 477 if (V2[0].type == ST_VECTOR_TMP) { 478 free (V2[0].vector[0].elements.Ptr);479 free (V2[0].vector);480 }478 free (V2[0].vector[0].elements.Ptr); 479 free (V2[0].vector); 480 } 481 481 482 482 clear_stack (V1); … … 501 501 // OP is the operation performed on *M1 and *M2 502 502 # define VS_FUNC(FTYPE,OP) { \ 503 if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) { \503 if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) { \ 504 504 CopyVector (OUT[0].vector, V1[0].vector); \ 505 505 opihi_flt *M1 = V1[0].vector[0].elements.Flt; \ … … 511 511 break; \ 512 512 } \ 513 if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) { \513 if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) { \ 514 514 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT); \ 515 515 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 521 521 break; \ 522 522 } \ 523 if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) { \523 if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) { \ 524 524 CopyVector (OUT[0].vector, V1[0].vector); \ 525 525 opihi_flt *M1 = V1[0].vector[0].elements.Flt; \ … … 541 541 break; \ 542 542 } \ 543 if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \543 if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \ 544 544 CopyVector (OUT[0].vector, V1[0].vector); \ 545 545 opihi_int *M1 = V1[0].vector[0].elements.Int; \ … … 554 554 555 555 switch (op[0]) { 556 case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);557 case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);558 case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);559 case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);560 case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);561 case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));562 case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));563 case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));564 case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));565 case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));566 case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);567 case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);568 case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));569 case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));570 case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);571 case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);572 case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);573 case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);574 case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);575 case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);576 default:577 snprintf (line, 512, "error: op %c not defined!", op[0]);578 push_error (line);579 return (FALSE);580 }556 case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2); 557 case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2); 558 case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2); 559 case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2); 560 case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2); 561 case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2)); 562 case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2)); 563 case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2)); 564 case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2)); 565 case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2)); 566 case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0); 567 case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0); 568 case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2)); 569 case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2)); 570 case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0); 571 case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0); 572 case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0); 573 case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0); 574 case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0); 575 case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0); 576 default: 577 snprintf (line, 512, "error: op %c not defined!", op[0]); 578 push_error (line); 579 return (FALSE); 580 } 581 581 # undef VS_FUNC 582 582 … … 584 584 585 585 if (V1[0].type == ST_VECTOR_TMP) { 586 free (V1[0].vector[0].elements.Ptr);587 free (V1[0].vector);588 }586 free (V1[0].vector[0].elements.Ptr); 587 free (V1[0].vector); 588 } 589 589 590 590 clear_stack (V1); … … 885 885 float *out = (float *)OUT[0].buffer[0].matrix.buffer; 886 886 887 # define MS_FUNC(OP) { \888 if (V2->type == ST_SCALAR_FLT) { \889 opihi_flt M2 = V2[0].FltValue; \887 # define MS_FUNC(OP) { \ 888 if (V2->type == ST_SCALAR_FLT) { \ 889 opihi_flt M2 = V2[0].FltValue; \ 890 890 for (i = 0; i < Npix; i++, out++, M1++) { \ 891 *out = OP; \892 } \893 break; \894 } \895 if (V2->type == ST_SCALAR_INT) { \896 opihi_int M2 = V2[0].IntValue; \891 *out = OP; \ 892 } \ 893 break; \ 894 } \ 895 if (V2->type == ST_SCALAR_INT) { \ 896 opihi_int M2 = V2[0].IntValue; \ 897 897 for (i = 0; i < Npix; i++, out++, M1++) { \ 898 *out = OP; \899 } \900 break; \901 } \898 *out = OP; \ 899 } \ 900 break; \ 901 } \ 902 902 } 903 903 … … 961 961 float *out = (float *)OUT[0].buffer[0].matrix.buffer; 962 962 963 # define SM_FUNC(OP) { \964 if (V1->type == ST_SCALAR_FLT) { \965 opihi_flt M1 = V1[0].FltValue; \963 # define SM_FUNC(OP) { \ 964 if (V1->type == ST_SCALAR_FLT) { \ 965 opihi_flt M1 = V1[0].FltValue; \ 966 966 for (i = 0; i < Npix; i++, out++, M2++) { \ 967 *out = OP; \968 } \969 break; \970 } \971 if (V1->type == ST_SCALAR_INT) { \972 opihi_int M1 = V1[0].IntValue; \967 *out = OP; \ 968 } \ 969 break; \ 970 } \ 971 if (V1->type == ST_SCALAR_INT) { \ 972 opihi_int M1 = V1[0].IntValue; \ 973 973 for (i = 0; i < Npix; i++, out++, M2++) { \ 974 *out = OP; \975 } \976 break; \977 } \974 *out = OP; \ 975 } \ 976 break; \ 977 } \ 978 978 } 979 979 … … 1023 1023 1024 1024 # define SS_FUNC(FTYPE,OP) { \ 1025 if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) { \1025 if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) { \ 1026 1026 opihi_flt M1 = V1[0].FltValue; \ 1027 1027 opihi_flt M2 = V2[0].FltValue; \ 1028 OUT[0].type = ST_SCALAR_FLT; \1028 OUT[0].type = ST_SCALAR_FLT; \ 1029 1029 OUT[0].FltValue = OP; \ 1030 1030 break; \ 1031 1031 } \ 1032 if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) { \1032 if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) { \ 1033 1033 opihi_flt M1 = V1[0].FltValue; \ 1034 1034 opihi_int M2 = V2[0].IntValue; \ 1035 OUT[0].type = ST_SCALAR_FLT; \1035 OUT[0].type = ST_SCALAR_FLT; \ 1036 1036 OUT[0].FltValue = OP; \ 1037 1037 break; \ 1038 1038 } \ 1039 if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) { \1039 if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) { \ 1040 1040 opihi_int M1 = V1[0].IntValue; \ 1041 1041 opihi_flt M2 = V2[0].FltValue; \ 1042 OUT[0].type = ST_SCALAR_FLT; \1042 OUT[0].type = ST_SCALAR_FLT; \ 1043 1043 OUT[0].FltValue = OP; \ 1044 1044 break; \ 1045 1045 } \ 1046 if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \1046 if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \ 1047 1047 opihi_int M1 = V1[0].IntValue; \ 1048 1048 opihi_int M2 = V2[0].IntValue; \ 1049 OUT[0].type = ST_SCALAR_FLT; \1049 OUT[0].type = ST_SCALAR_FLT; \ 1050 1050 OUT[0].FltValue = OP; \ 1051 1051 break; \ 1052 1052 } \ 1053 if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \1053 if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \ 1054 1054 opihi_int M1 = V1[0].IntValue; \ 1055 1055 opihi_int M2 = V2[0].IntValue; \ 1056 OUT[0].type = ST_SCALAR_INT; \1056 OUT[0].type = ST_SCALAR_INT; \ 1057 1057 OUT[0].IntValue = OP; \ 1058 1058 break; \ … … 1061 1061 1062 1062 switch (op[0]) { 1063 case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);1064 case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);1065 case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);1066 case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);1067 case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);1068 case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));1069 case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));1070 case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));1071 case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));1072 case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));1073 case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);1074 case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);1075 case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));1076 case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));1077 case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);1078 case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);1079 case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);1080 case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);1081 case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);1082 case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);1083 default:1084 snprintf (line, 512, "error: op %c not defined!", op[0]);1085 push_error (line);1086 return (FALSE);1087 }1063 case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2); 1064 case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2); 1065 case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2); 1066 case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2); 1067 case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2); 1068 case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2)); 1069 case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2)); 1070 case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2)); 1071 case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2)); 1072 case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2)); 1073 case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0); 1074 case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0); 1075 case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2)); 1076 case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2)); 1077 case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0); 1078 case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0); 1079 case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0); 1080 case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0); 1081 case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0); 1082 case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0); 1083 default: 1084 snprintf (line, 512, "error: op %c not defined!", op[0]); 1085 push_error (line); 1086 return (FALSE); 1087 } 1088 1088 # undef SS_FUNC 1089 1089 … … 1153 1153 } 1154 1154 1155 1156 1155 int S_unary (StackVar *OUT, StackVar *V1, char *op) { 1157 1156 1158 1157 char line[512]; // this is only used to report an error 1159 1158 1160 # define S_FUNC(OP,FTYPE) { \1161 if (V1->type == ST_SCALAR_FLT) { \1162 opihi_flt M1 = V1[0].FltValue; \1163 OUT[0].type = ST_SCALAR_FLT; \1164 OUT[0].FltValue = OP; \1165 clear_stack (V1); \1166 return (TRUE); \1167 } \1159 # define S_FUNC(OP,FTYPE) { \ 1160 if (V1->type == ST_SCALAR_FLT) { \ 1161 opihi_flt M1 = V1[0].FltValue; \ 1162 OUT[0].type = ST_SCALAR_FLT; \ 1163 OUT[0].FltValue = OP; \ 1164 clear_stack (V1); \ 1165 return (TRUE); \ 1166 } \ 1168 1167 if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) { \ 1169 opihi_int M1 = V1[0].IntValue; \1170 OUT[0].type = ST_SCALAR_FLT; \1171 OUT[0].FltValue = OP; \1172 clear_stack (V1); \1173 return (TRUE); \1174 } \1168 opihi_int M1 = V1[0].IntValue; \ 1169 OUT[0].type = ST_SCALAR_FLT; \ 1170 OUT[0].FltValue = OP; \ 1171 clear_stack (V1); \ 1172 return (TRUE); \ 1173 } \ 1175 1174 if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) { \ 1176 opihi_int M1 = V1[0].IntValue; \1177 OUT[0].type = ST_SCALAR_INT; \1178 OUT[0].IntValue = OP; \1179 clear_stack (V1); \1180 return (TRUE); \1181 } \1175 opihi_int M1 = V1[0].IntValue; \ 1176 OUT[0].type = ST_SCALAR_INT; \ 1177 OUT[0].IntValue = OP; \ 1178 clear_stack (V1); \ 1179 return (TRUE); \ 1180 } \ 1182 1181 } 1183 1182 … … 1211 1210 if (!strcmp (op, "dacos")) S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT); 1212 1211 if (!strcmp (op, "datan")) S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT); 1213 if (!strcmp (op, "rnd")) S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT); 1212 if (!strcmp (op, "rnd")) S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT); 1213 if (!strcmp (op, "drnd")) S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT); 1214 if (!strcmp (op, "lrnd")) S_FUNC(0*M1 + lrand48(), ST_SCALAR_INT); 1215 if (!strcmp (op, "mrnd")) S_FUNC(0*M1 + mrand48(), ST_SCALAR_INT); 1214 1216 if (!strcmp (op, "not")) S_FUNC(!(M1), ST_SCALAR_INT); 1215 1217 if (!strcmp (op, "--")) S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed, … … 1235 1237 OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/ 1236 1238 1237 # define V_FUNC(OP,FTYPE) { \1238 if (V1->vector->type == OPIHI_FLT) { \1239 CopyVector (OUT[0].vector, V1[0].vector); \1240 opihi_flt *M1 = V1[0].vector[0].elements.Flt; \1241 opihi_flt *out = OUT[0].vector[0].elements.Flt; \1242 for (i = 0; i < Nx; i++, out++, M1++) { \1243 *out = OP; \1244 } \1245 goto escape; \1246 } \1239 # define V_FUNC(OP,FTYPE) { \ 1240 if (V1->vector->type == OPIHI_FLT) { \ 1241 CopyVector (OUT[0].vector, V1[0].vector); \ 1242 opihi_flt *M1 = V1[0].vector[0].elements.Flt; \ 1243 opihi_flt *out = OUT[0].vector[0].elements.Flt; \ 1244 for (i = 0; i < Nx; i++, out++, M1++) { \ 1245 *out = OP; \ 1246 } \ 1247 goto escape; \ 1248 } \ 1247 1249 if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) { \ 1248 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT); \1249 opihi_int *M1 = V1[0].vector[0].elements.Int; \1250 opihi_flt *out = OUT[0].vector[0].elements.Flt; \1251 for (i = 0; i < Nx; i++, out++, M1++) { \1252 *out = OP; \1253 } \1254 goto escape; \1255 } \1250 MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT); \ 1251 opihi_int *M1 = V1[0].vector[0].elements.Int; \ 1252 opihi_flt *out = OUT[0].vector[0].elements.Flt; \ 1253 for (i = 0; i < Nx; i++, out++, M1++) { \ 1254 *out = OP; \ 1255 } \ 1256 goto escape; \ 1257 } \ 1256 1258 if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) { \ 1257 CopyVector (OUT[0].vector, V1[0].vector); \1258 opihi_int *M1 = V1[0].vector[0].elements.Int; \1259 opihi_int *out = OUT[0].vector[0].elements.Int; \1260 for (i = 0; i < Nx; i++, out++, M1++) { \1261 *out = OP; \1262 } \1263 goto escape; \1259 CopyVector (OUT[0].vector, V1[0].vector); \ 1260 opihi_int *M1 = V1[0].vector[0].elements.Int; \ 1261 opihi_int *out = OUT[0].vector[0].elements.Int; \ 1262 for (i = 0; i < Nx; i++, out++, M1++) { \ 1263 *out = OP; \ 1264 } \ 1265 goto escape; \ 1264 1266 } } 1265 1267 … … 1294 1296 if (!strcmp (op, "datan")) V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT); 1295 1297 if (!strcmp (op, "rnd")) V_FUNC(drand48(), ST_SCALAR_FLT); 1298 if (!strcmp (op, "drnd")) V_FUNC(drand48(), ST_SCALAR_FLT); 1299 if (!strcmp (op, "lrnd")) V_FUNC(lrand48(), ST_SCALAR_INT); 1300 if (!strcmp (op, "mrnd")) V_FUNC(mrand48(), ST_SCALAR_INT); 1296 1301 if (!strcmp (op, "ramp")) V_FUNC(i, ST_SCALAR_INT); 1297 1302 if (!strcmp (op, "zero")) V_FUNC(0, ST_SCALAR_INT); … … 1320 1325 } 1321 1326 1327 # define M_FUNC(OP) { for (i = 0; i < Npix; i++, out++, M1++) { *out = (OP); }} 1328 1322 1329 int M_unary (StackVar *OUT, StackVar *V1, char *op) { 1323 1330 … … 1337 1344 M1 = (float *) V1[0].buffer[0].matrix.buffer; 1338 1345 out = (float *)OUT[0].buffer[0].matrix.buffer; 1339 1346 1347 // if (!strcmp (op, "rint")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }} 1348 1340 1349 if (!strcmp (op, "=")) { } 1341 if (!strcmp (op, "abs")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = fabs(*M1); }} 1342 if (!strcmp (op, "int")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = (opihi_flt)(long long)(*M1); }} 1343 1344 if (!strcmp (op, "floor")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = floor (*M1); }} 1345 if (!strcmp (op, "ceil")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = ceil (*M1); }} 1346 // if (!strcmp (op, "rint")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }} 1347 1348 if (!strcmp (op, "exp")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = exp(*M1); }} 1349 if (!strcmp (op, "ten")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = pow(10.0,*M1); }} 1350 if (!strcmp (op, "log")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = log10(*M1); }} 1351 if (!strcmp (op, "ln")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = log(*M1); }} 1352 if (!strcmp (op, "sqrt")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = sqrt(*M1); }} 1353 if (!strcmp (op, "erf")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = erf(*M1); }} 1354 1355 if (!strcmp (op, "sinh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = sinh(*M1); }} 1356 if (!strcmp (op, "cosh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = cosh(*M1); }} 1357 if (!strcmp (op, "asinh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asinh(*M1); }} 1358 if (!strcmp (op, "acosh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acosh(*M1); }} 1359 if (!strcmp (op, "lgamma")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = lgamma(*M1); }} 1360 1361 if (!strcmp (op, "sin")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1); }} 1362 if (!strcmp (op, "cos")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1); }} 1363 if (!strcmp (op, "tan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1); }} 1364 if (!strcmp (op, "dsin")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1*RAD_DEG); }} 1365 if (!strcmp (op, "dcos")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1*RAD_DEG); }} 1366 if (!strcmp (op, "dtan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1*RAD_DEG); }} 1367 if (!strcmp (op, "asin")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1); }} 1368 if (!strcmp (op, "acos")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1); }} 1369 if (!strcmp (op, "atan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1); }} 1370 if (!strcmp (op, "dasin")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1)*DEG_RAD; }} 1371 if (!strcmp (op, "dacos")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1)*DEG_RAD; }} 1372 if (!strcmp (op, "datan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1)*DEG_RAD; }} 1373 if (!strcmp (op, "not")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = !(*M1); }} 1374 if (!strcmp (op, "--")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = -(*M1); }} 1375 if (!strcmp (op, "rnd")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = drand48(); }} 1376 if (!strcmp (op, "ramp")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = i; }} 1377 if (!strcmp (op, "zero")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = 0; }} 1378 if (!strcmp (op, "isinf")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = !finite(*M1); }} 1379 if (!strcmp (op, "isnan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = isnan(*M1); }} 1350 if (!strcmp (op, "abs")) M_FUNC(fabs(*M1)); 1351 if (!strcmp (op, "int")) M_FUNC((opihi_flt)(long long)(*M1)); 1352 if (!strcmp (op, "floor")) M_FUNC(floor (*M1)); 1353 if (!strcmp (op, "ceil")) M_FUNC(ceil (*M1)); 1354 if (!strcmp (op, "exp")) M_FUNC(exp(*M1)); 1355 if (!strcmp (op, "ten")) M_FUNC(pow(10.0,*M1)); 1356 if (!strcmp (op, "log")) M_FUNC(log10(*M1)); 1357 if (!strcmp (op, "ln")) M_FUNC(log(*M1)); 1358 if (!strcmp (op, "sqrt")) M_FUNC(sqrt(*M1)); 1359 if (!strcmp (op, "erf")) M_FUNC(erf(*M1)); 1360 if (!strcmp (op, "sinh")) M_FUNC(sinh(*M1)); 1361 if (!strcmp (op, "cosh")) M_FUNC(cosh(*M1)); 1362 if (!strcmp (op, "asinh")) M_FUNC(asinh(*M1)); 1363 if (!strcmp (op, "acosh")) M_FUNC(acosh(*M1)); 1364 if (!strcmp (op, "lgamma")) M_FUNC(lgamma(*M1)); 1365 if (!strcmp (op, "sin")) M_FUNC(sin(*M1)); 1366 if (!strcmp (op, "cos")) M_FUNC(cos(*M1)); 1367 if (!strcmp (op, "tan")) M_FUNC(tan(*M1)); 1368 if (!strcmp (op, "dsin")) M_FUNC(sin(*M1*RAD_DEG)); 1369 if (!strcmp (op, "dcos")) M_FUNC(cos(*M1*RAD_DEG)); 1370 if (!strcmp (op, "dtan")) M_FUNC(tan(*M1*RAD_DEG)); 1371 if (!strcmp (op, "asin")) M_FUNC(asin(*M1)); 1372 if (!strcmp (op, "acos")) M_FUNC(acos(*M1)); 1373 if (!strcmp (op, "atan")) M_FUNC(atan(*M1)); 1374 if (!strcmp (op, "dasin")) M_FUNC(asin(*M1)*DEG_RAD); 1375 if (!strcmp (op, "dacos")) M_FUNC(acos(*M1)*DEG_RAD); 1376 if (!strcmp (op, "datan")) M_FUNC(atan(*M1)*DEG_RAD); 1377 if (!strcmp (op, "not")) M_FUNC(!(*M1)); 1378 if (!strcmp (op, "--")) M_FUNC(-(*M1)); 1379 if (!strcmp (op, "rnd")) M_FUNC(drand48()); 1380 if (!strcmp (op, "drnd")) M_FUNC(drand48()); 1381 if (!strcmp (op, "lrnd")) M_FUNC(lrand48()); 1382 if (!strcmp (op, "mrnd")) M_FUNC(mrand48()); 1383 if (!strcmp (op, "ramp")) M_FUNC(i); 1384 if (!strcmp (op, "zero")) M_FUNC(0); 1385 if (!strcmp (op, "isinf")) M_FUNC(!finite(*M1)); 1386 if (!strcmp (op, "isnan")) M_FUNC(isnan(*M1)); 1380 1387 1381 1388 /* xrm and yrm only make sense for 2D matrices. see special meaning for vectors */
Note:
See TracChangeset
for help on using the changeset viewer.
