IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20912


Ignore:
Timestamp:
Dec 7, 2008, 1:19:02 PM (17 years ago)
Author:
eugene
Message:

fixed so int math is not forced in unexpected cases: int/int -> flt, atan2(int,int) -> flt, pow(int,int) -> flt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c

    r20873 r20912  
    2828  // set up the possible operations : int OP int -> int, all else yield float
    2929  // OP is the operation performed on *M1 and *M2
    30 # define VV_FUNC(OP) {                                                  \
     30# define VV_FUNC(FTYPE,OP) {                                            \
    3131    if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT)) { \
    3232      CopyVector (OUT[0].vector, V1[0].vector);                         \
     
    5959      break;                                                            \
    6060    }                                                                   \
     61    if ((FTYPE == 'S') && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
     62      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
     63      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     64      opihi_int *M2  =  V2[0].vector[0].elements.Int;                   \
     65      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     66      for (i = 0; i < Nx; i++, out++, M1++, M2++) {                     \
     67        *out = OP;                                                      \
     68      }                                                                 \
     69      break;                                                            \
     70    }                                                                   \
    6171    if ((V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
    6272      CopyVector (OUT[0].vector, V1[0].vector);                         \
     
    6575      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
    6676      for (i = 0; i < Nx; i++, out++, M1++, M2++) {                     \
    67         *out = OP;                                                      \
    68       }                                                                 \
    69       break;                                                            \
    70     } }
     77        *out = OP;                                                      \
     78      }                                                                 \
     79      break;                                                            \
     80    }                                                                   \
     81  }
    7182
    7283  switch (op[0]) {
    73     case '+': VV_FUNC(*M1 + *M2);
    74     case '-': VV_FUNC(*M1 - *M2);
    75     case '*': VV_FUNC(*M1 * *M2);
    76     case '/': VV_FUNC(*M1 / *M2);
    77     case '%': VV_FUNC((int)*M1 % (int)*M2);
    78     case '^': VV_FUNC(pow (*M1, *M2));
    79     case '@': VV_FUNC(DEG_RAD*atan2 (*M1, *M2));
    80     case 'D': VV_FUNC(MIN (*M1, *M2));
    81     case 'U': VV_FUNC(MAX (*M1, *M2));
    82     case '<': VV_FUNC((*M1 < *M2) ? 1 : 0);
    83     case '>': VV_FUNC((*M1 > *M2) ? 1 : 0);
    84     case '&': VV_FUNC(((int)*M1 & (int)*M2));
    85     case '|': VV_FUNC(((int)*M1 | (int)*M2));
    86     case 'E': VV_FUNC((*M1 == *M2) ? 1 : 0);
    87     case 'N': VV_FUNC((*M1 != *M2) ? 1 : 0);
    88     case 'L': VV_FUNC((*M1 <= *M2) ? 1 : 0);
    89     case 'G': VV_FUNC((*M1 >= *M2) ? 1 : 0);
    90     case 'A': VV_FUNC((*M1 && *M2) ? 1 : 0);
    91     case 'O': VV_FUNC((*M1 || *M2) ? 1 : 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', (int)*M1 % (int)*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', ((int)*M1 & (int)*M2));
     96    case '|': VV_FUNC('s', ((int)*M1 | (int)*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);
    92103    default:
    93104      sprintf (line, "error: op %c not defined!", op[0]);
     
    127138  // set up the possible operations : int OP int -> int, all else yield float
    128139  // OP is the operation performed on *M1 and *M2
    129 # define SV_FUNC(OP)                                            \
    130   if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) {   \
    131     CopyVector (OUT[0].vector, V2[0].vector);                   \
    132     opihi_flt  M1  =  V1[0].FltValue;                           \
    133     opihi_flt *M2  =  V2[0].vector[0].elements.Flt;             \
    134     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    135     for (i = 0; i < Nx; i++, out++, M2++) {                     \
    136       *out = OP;                                                \
    137     }                                                           \
    138     break;                                                      \
    139   }                                                             \
    140   if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) {   \
    141     MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);       \
    142     opihi_flt  M1  =  V1[0].FltValue;                           \
    143     opihi_int *M2  =  V2[0].vector[0].elements.Int;             \
    144     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    145     for (i = 0; i < Nx; i++, out++, M2++) {                     \
    146       *out = OP;                                                \
    147     }                                                           \
    148     break;                                                      \
    149   }                                                             \
    150   if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) {   \
    151     CopyVector (OUT[0].vector, V2[0].vector);                   \
    152     opihi_int  M1  =  V1[0].IntValue;                           \
    153     opihi_flt *M2  =  V2[0].vector[0].elements.Flt;             \
    154     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    155     for (i = 0; i < Nx; i++, out++, M2++) {                     \
    156       *out = OP;                                                \
    157     }                                                           \
    158     break;                                                      \
    159   }                                                             \
    160   if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) {   \
    161     CopyVector (OUT[0].vector, V2[0].vector);                   \
    162     opihi_int  M1  =  V1[0].IntValue;                           \
    163     opihi_int *M2  =  V2[0].vector[0].elements.Int;             \
    164     opihi_int *out = OUT[0].vector[0].elements.Int;             \
    165     for (i = 0; i < Nx; i++, out++, M2++) {                     \
    166       *out = OP;                                                \
    167     }                                                           \
    168     break;                                                      \
     140# define SV_FUNC(FTYPE,OP) {                                            \
     141    if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) {         \
     142      CopyVector (OUT[0].vector, V2[0].vector);                         \
     143      opihi_flt  M1  =  V1[0].FltValue;                                 \
     144      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;                   \
     145      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     146      for (i = 0; i < Nx; i++, out++, M2++) {                           \
     147        *out = OP;                                                      \
     148      }                                                                 \
     149      break;                                                            \
     150    }                                                                   \
     151    if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) {         \
     152      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
     153      opihi_flt  M1  =  V1[0].FltValue;                                 \
     154      opihi_int *M2  =  V2[0].vector[0].elements.Int;                   \
     155      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     156      for (i = 0; i < Nx; i++, out++, M2++) {                           \
     157        *out = OP;                                                      \
     158      }                                                                 \
     159      break;                                                            \
     160    }                                                                   \
     161    if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) {         \
     162      CopyVector (OUT[0].vector, V2[0].vector);                         \
     163      opihi_int  M1  =  V1[0].IntValue;                                 \
     164      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;                   \
     165      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     166      for (i = 0; i < Nx; i++, out++, M2++) {                           \
     167        *out = OP;                                                      \
     168      }                                                                 \
     169      break;                                                            \
     170    }                                                                   \
     171    if ((FTYPE == 'S') && (V1->type == 's') && (V2->vector->type != OPIHI_FLT)) { \
     172      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
     173      opihi_int  M1  =  V1[0].IntValue;                                 \
     174      opihi_int *M2  =  V2[0].vector[0].elements.Int;                   \
     175      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     176      for (i = 0; i < Nx; i++, out++, M2++) {                           \
     177        *out = OP;                                                      \
     178      }                                                                 \
     179      break;                                                            \
     180    }                                                                   \
     181    if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) {         \
     182      CopyVector (OUT[0].vector, V2[0].vector);                         \
     183      opihi_int  M1  =  V1[0].IntValue;                                 \
     184      opihi_int *M2  =  V2[0].vector[0].elements.Int;                   \
     185      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     186      for (i = 0; i < Nx; i++, out++, M2++) {                           \
     187        *out = OP;                                                      \
     188      }                                                                 \
     189      break;                                                            \
     190    }                                                                   \
    169191  }
    170192
    171193  switch (op[0]) {
    172     case '+': SV_FUNC(M1 + *M2);
    173     case '-': SV_FUNC(M1 - *M2);
    174     case '*': SV_FUNC(M1 * *M2);
    175     case '/': SV_FUNC(M1 / *M2);
    176     case '%': SV_FUNC((int) M1 % (int) *M2);
    177     case '^': SV_FUNC(pow (M1, *M2));
    178     case '@': SV_FUNC(DEG_RAD*atan2 (M1, *M2));
    179     case 'D': SV_FUNC(MIN (M1, *M2));
    180     case 'U': SV_FUNC(MAX (M1, *M2));
    181     case '<': SV_FUNC((M1 < *M2) ? 1 : 0);
    182     case '>': SV_FUNC((M1 > *M2) ? 1 : 0);
    183     case '&': SV_FUNC(((int)M1 & (int)*M2));
    184     case '|': SV_FUNC(((int)M1 | (int)*M2));
    185     case 'E': SV_FUNC((M1 == *M2) ? 1 : 0);
    186     case 'N': SV_FUNC((M1 != *M2) ? 1 : 0);
    187     case 'L': SV_FUNC((M1 <= *M2) ? 1 : 0);
    188     case 'G': SV_FUNC((M1 >= *M2) ? 1 : 0);
    189     case 'A': SV_FUNC((M1 && *M2) ? 1 : 0);
    190     case 'O': SV_FUNC((M1 || *M2) ? 1 : 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', (int) M1 % (int) *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', ((int)M1 & (int)*M2));
     206    case '|': SV_FUNC('s', ((int)M1 | (int)*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);
    191213    default:
    192214      sprintf (line, "error: op %c not defined!", op[0]);
     
    222244  // set up the possible operations : int OP int -> int, all else yield float
    223245  // OP is the operation performed on *M1 and *M2
    224 # define VS_FUNC(OP)                                            \
    225   if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) {   \
    226     CopyVector (OUT[0].vector, V1[0].vector);                   \
    227     opihi_flt *M1  =  V1[0].vector[0].elements.Flt;             \
    228     opihi_flt  M2  =  V2[0].FltValue;                           \
    229     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    230     for (i = 0; i < Nx; i++, out++, M1++) {                     \
    231       *out = OP;                                                \
    232     }                                                           \
    233     break;                                                      \
    234   }                                                             \
    235   if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) {   \
    236     MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);       \
    237     opihi_int *M1  =  V1[0].vector[0].elements.Int;             \
    238     opihi_flt  M2  =  V2[0].FltValue;                           \
    239     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    240     for (i = 0; i < Nx; i++, out++, M1++) {                     \
    241       *out = OP;                                                \
    242     }                                                           \
    243     break;                                                      \
    244   }                                                             \
    245   if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) {   \
    246     CopyVector (OUT[0].vector, V1[0].vector);                   \
    247     opihi_flt *M1  =  V1[0].vector[0].elements.Flt;             \
    248     opihi_int  M2  =  V2[0].IntValue;                           \
    249     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    250     for (i = 0; i < Nx; i++, out++, M1++) {                     \
    251       *out = OP;                                                \
    252     }                                                           \
    253     break;                                                      \
    254   }                                                             \
    255   if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) {   \
    256     CopyVector (OUT[0].vector, V1[0].vector);                   \
    257     opihi_int *M1  =  V1[0].vector[0].elements.Int;             \
    258     opihi_int  M2  =  V2[0].IntValue;                           \
    259     opihi_int *out = OUT[0].vector[0].elements.Int;             \
    260     for (i = 0; i < Nx; i++, out++, M1++) {                     \
    261       *out = OP;                                                \
    262     }                                                           \
    263     break;                                                      \
     246# define VS_FUNC(FTYPE,OP) {                                            \
     247    if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) {         \
     248      CopyVector (OUT[0].vector, V1[0].vector);                         \
     249      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     250      opihi_flt  M2  =  V2[0].FltValue;                                 \
     251      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     252      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     253        *out = OP;                                                      \
     254      }                                                                 \
     255      break;                                                            \
     256    }                                                                   \
     257    if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) {         \
     258      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
     259      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     260      opihi_flt  M2  =  V2[0].FltValue;                                 \
     261      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     262      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     263        *out = OP;                                                      \
     264      }                                                                 \
     265      break;                                                            \
     266    }                                                                   \
     267    if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) {         \
     268      CopyVector (OUT[0].vector, V1[0].vector);                         \
     269      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     270      opihi_int  M2  =  V2[0].IntValue;                                 \
     271      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     272      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     273        *out = OP;                                                      \
     274      }                                                                 \
     275      break;                                                            \
     276    }                                                                   \
     277    if ((FTYPE == 'S') && (V2->type == 's') && (V1->vector->type != OPIHI_FLT)) { \
     278      CopyVector (OUT[0].vector, V1[0].vector);                         \
     279      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     280      opihi_int  M2  =  V2[0].IntValue;                                 \
     281      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     282      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     283        *out = OP;                                                      \
     284      }                                                                 \
     285      break;                                                            \
     286    }                                                                   \
     287    if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) {         \
     288      CopyVector (OUT[0].vector, V1[0].vector);                         \
     289      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     290      opihi_int  M2  =  V2[0].IntValue;                                 \
     291      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     292      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     293        *out = OP;                                                      \
     294      }                                                                 \
     295      break;                                                            \
     296    }                                                                   \
    264297  }
    265298
    266299  switch (op[0]) {
    267     case '+': VS_FUNC(*M1 + M2);
    268     case '-': VS_FUNC(*M1 - M2);
    269     case '*': VS_FUNC(*M1 * M2);
    270     case '/': VS_FUNC(*M1 / M2);
    271     case '%': VS_FUNC((int) *M1 % (int) M2);
    272     case '^': VS_FUNC(pow (*M1, M2));
    273     case '@': VS_FUNC(DEG_RAD*atan2 (*M1, M2));
    274     case 'D': VS_FUNC(MIN (*M1, M2));
    275     case 'U': VS_FUNC(MAX (*M1, M2));
    276     case '<': VS_FUNC((*M1 < M2) ? 1 : 0);
    277     case '>': VS_FUNC((*M1 > M2) ? 1 : 0);
    278     case '&': VS_FUNC(((int)*M1 & (int)M2));
    279     case '|': VS_FUNC(((int)*M1 | (int)M2));
    280     case 'E': VS_FUNC((*M1 == M2) ? 1 : 0);
    281     case 'N': VS_FUNC((*M1 != M2) ? 1 : 0);
    282     case 'L': VS_FUNC((*M1 <= M2) ? 1 : 0);
    283     case 'G': VS_FUNC((*M1 >= M2) ? 1 : 0);
    284     case 'A': VS_FUNC((*M1 && M2) ? 1 : 0);
    285     case 'O': VS_FUNC((*M1 || M2) ? 1 : 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', (int) *M1 % (int) 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', ((int)*M1 & (int)M2));
     312    case '|': VS_FUNC('s', ((int)*M1 | (int)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);
    286319    default:
    287320      sprintf (line, "error: op %c not defined!", op[0]);
     
    331364
    332365  float     *M1  = (float *) V1[0].buffer[0].matrix.buffer;
    333   opihi_flt *M2  = V2[0].vector[0].elements.Flt;
    334366  float     *out = (float *)OUT[0].buffer[0].matrix.buffer;
    335367
    336 # define MV_FUNC(OP)                            \
    337   for (i = 0; i < Ny; i++, M2++) {              \
    338     for (j = 0; j < Nx; j++, out++, M1++) {     \
    339       *out = OP;                                \
    340     }                                           \
    341   }                                             \
    342   break;
     368# define MV_FUNC(OP) {                                  \
     369    if (V2->vector->type == OPIHI_FLT) {                \
     370      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;   \
     371      for (i = 0; i < Ny; i++, M2++) {                  \
     372        for (j = 0; j < Nx; j++, out++, M1++) {         \
     373          *out = OP;                                    \
     374        }                                               \
     375      }                                                 \
     376      break;                                            \
     377    }                                                   \
     378    if (V2->vector->type != OPIHI_FLT) {                \
     379      opihi_int *M2  =  V2[0].vector[0].elements.Int;   \
     380      for (i = 0; i < Ny; i++, M2++) {                  \
     381        for (j = 0; j < Nx; j++, out++, M1++) {         \
     382          *out = OP;                                    \
     383        }                                               \
     384      }                                                 \
     385      break;                                            \
     386    }                                                   \
     387  }
    343388
    344389  switch (op[0]) {
     
    346391    case '-': MV_FUNC(*M1 - *M2);
    347392    case '*': MV_FUNC(*M1 * *M2);
    348     case '/': MV_FUNC(*M1 / *M2);
     393    case '/': MV_FUNC(*M1 / (opihi_flt) *M2);
    349394    case '%': MV_FUNC((int) *M1 % (int) *M2);
    350395    case '^': MV_FUNC(pow (*M1, *M2));
     
    367412      return (FALSE);
    368413  }
     414# undef MV_FUNC
    369415
    370416  /** free up any temporary buffers: **/
     
    409455  OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
    410456
    411   opihi_flt *M1  = V1[0].vector[0].elements.Flt;
    412457  float     *M2  = (float *) V2[0].buffer[0].matrix.buffer;
    413458  float     *out = (float *)OUT[0].buffer[0].matrix.buffer;
    414459
    415 # define VM_FUNC(OP)                                    \
    416   for (i = 0; i < Ny; i++) {                            \
    417     M1  = V1[0].vector[0].elements.Flt;                 \
    418     for (j = 0; j < Nx; j++, out++, M1++, M2++) {       \
    419       *out = OP;                                        \
     460# define VM_FUNC(OP) {                                  \
     461    if (V1->vector->type == OPIHI_FLT) {                \
     462      for (i = 0; i < Ny; i++) {                        \
     463        opihi_flt *M1  = V1[0].vector[0].elements.Flt;  \
     464        for (j = 0; j < Nx; j++, out++, M1++, M2++) {   \
     465          *out = OP;                                    \
     466        }                                               \
     467      }                                                 \
     468      break;                                            \
    420469    }                                                   \
    421   }                                                     \
    422   break;
     470    if (V1->vector->type != OPIHI_FLT) {                \
     471      for (i = 0; i < Ny; i++) {                        \
     472        opihi_int *M1  =  V1[0].vector[0].elements.Int; \
     473        for (j = 0; j < Nx; j++, out++, M1++, M2++) {   \
     474          *out = OP;                                    \
     475        }                                               \
     476      }                                                 \
     477      break;                                            \
     478    }                                                   \
     479  }
    423480
    424481  switch (op[0]) {
     
    426483    case '-': VM_FUNC(*M1 - *M2);
    427484    case '*': VM_FUNC(*M1 * *M2);
    428     case '/': VM_FUNC(*M1 / *M2);
     485    case '/': VM_FUNC(*M1 / (opihi_flt) *M2);
    429486    case '%': VM_FUNC((int) *M1 % (int) *M2);
    430487    case '^': VM_FUNC(pow (*M1, *M2));
     
    447504      return (FALSE);
    448505  }
     506# undef VM_FUNC
    449507
    450508  /** free up any temporary buffers: **/
     
    505563    case '-': MM_FUNC(*M1 - *M2);
    506564    case '*': MM_FUNC(*M1 * *M2);
    507     case '/': MM_FUNC(*M1 / *M2);
     565    case '/': MM_FUNC(*M1 / (float) *M2);
    508566    case '%': MM_FUNC((int) *M1 % (int) *M2);
    509567    case '^': MM_FUNC(pow (*M1, *M2));
     
    567625
    568626  float *M1    = (float *)V1[0].buffer[0].matrix.buffer;
    569   opihi_flt M2 = V2[0].FltValue;
    570627  float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
    571628
    572 # define MS_FUNC(OP)                            \
    573   for (i = 0; i < Nx*Ny; i++, out++, M1++) {    \
    574     *out = OP;                                  \
    575   }                                             \
    576   break;
     629# define MS_FUNC(OP) {                                  \
     630    if (V2->type == 's')  {                             \
     631      opihi_flt M2 = V2[0].FltValue;                    \
     632      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     633        *out = OP;                                      \
     634      }                                                 \
     635      break;                                            \
     636    }                                                   \
     637    if (V2->type == 'S')  {                             \
     638      opihi_int M2 = V2[0].IntValue;                    \
     639      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     640        *out = OP;                                      \
     641      }                                                 \
     642      break;                                            \
     643    }                                                   \
     644  }
    577645
    578646  switch (op[0]) {
     
    580648    case '-': MS_FUNC(*M1 - M2);
    581649    case '*': MS_FUNC(*M1 * M2);
    582     case '/': MS_FUNC(*M1 / M2);
     650    case '/': MS_FUNC(*M1 / (float) M2);
    583651    case '%': MS_FUNC((int) *M1 % (int) M2);
    584652    case '^': MS_FUNC(pow (*M1, M2));
     
    632700  OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
    633701
    634   opihi_flt M1 = V1[0].FltValue;
    635702  float *M2    = (float *)V2[0].buffer[0].matrix.buffer;
    636703  float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
    637704
    638 # define SM_FUNC(OP)                            \
    639   for (i = 0; i < Nx*Ny; i++, out++, M2++)      \
    640     *out = OP;                                  \
    641   break;
     705# define SM_FUNC(OP) {                                  \
     706    if (V1->type == 's')  {                             \
     707      opihi_flt M1 = V1[0].FltValue;                    \
     708      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     709        *out = OP;                                      \
     710      }                                                 \
     711      break;                                            \
     712    }                                                   \
     713    if (V1->type == 'S')  {                             \
     714      opihi_int M1 = V1[0].IntValue;                    \
     715      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     716        *out = OP;                                      \
     717      }                                                 \
     718      break;                                            \
     719    }                                                   \
     720  }
    642721
    643722  switch (op[0]) {
     
    645724    case '-': SM_FUNC(M1 - *M2);
    646725    case '*': SM_FUNC(M1 * *M2);
    647     case '/': SM_FUNC(M1 / *M2);
     726    case '/': SM_FUNC(M1 / (float) *M2);
    648727    case '%': SM_FUNC((int) M1 % (int) *M2);
    649728    case '^': SM_FUNC(pow (M1, *M2));
     
    684763  char line[512]; // this is only used to report an error
    685764
    686 # define SS_FUNC(OP)                            \
    687   if ((V1->type == 'S') && (V2->type == 'S')) { \
    688     opihi_flt M1 = V1[0].FltValue;              \
    689     opihi_flt M2 = V2[0].FltValue;              \
    690     OUT[0].type = 'S';                          \
    691     OUT[0].FltValue = OP;                       \
    692     break;                                      \
    693   }                                             \
    694   if ((V1->type == 'S') && (V2->type == 's')) { \
    695     opihi_flt M1 = V1[0].FltValue;              \
    696     opihi_int M2 = V2[0].IntValue;              \
    697     OUT[0].type = 'S';                          \
    698     OUT[0].FltValue = OP;                       \
    699     break;                                      \
    700   }                                             \
    701   if ((V1->type == 's') && (V2->type == 'S')) { \
    702     opihi_int M1 = V1[0].IntValue;              \
    703     opihi_flt M2 = V2[0].FltValue;              \
    704     OUT[0].type = 'S';                          \
    705     OUT[0].FltValue = OP;                       \
    706     break;                                      \
    707   }                                             \
    708   if ((V1->type == 's') && (V2->type == 's')) { \
    709     opihi_int M1 = V1[0].IntValue;              \
    710     opihi_int M2 = V2[0].IntValue;              \
    711     OUT[0].type = 's';                          \
    712     OUT[0].IntValue = OP;                       \
    713     break;                                      \
     765# define SS_FUNC(FTYPE,OP) {                                            \
     766    if ((V1->type == 'S') && (V2->type == 'S')) {                       \
     767      opihi_flt M1 = V1[0].FltValue;                                    \
     768      opihi_flt M2 = V2[0].FltValue;                                    \
     769      OUT[0].type = 'S';                                                \
     770      OUT[0].FltValue = OP;                                             \
     771      break;                                                            \
     772    }                                                                   \
     773    if ((V1->type == 'S') && (V2->type == 's')) {                       \
     774      opihi_flt M1 = V1[0].FltValue;                                    \
     775      opihi_int M2 = V2[0].IntValue;                                    \
     776      OUT[0].type = 'S';                                                \
     777      OUT[0].FltValue = OP;                                             \
     778      break;                                                            \
     779    }                                                                   \
     780    if ((V1->type == 's') && (V2->type == 'S')) {                       \
     781      opihi_int M1 = V1[0].IntValue;                                    \
     782      opihi_flt M2 = V2[0].FltValue;                                    \
     783      OUT[0].type = 'S';                                                \
     784      OUT[0].FltValue = OP;                                             \
     785      break;                                                            \
     786    }                                                                   \
     787    if ((FTYPE == 'S') && (V1->type == 's') && (V2->type == 's')) {     \
     788      opihi_int M1 = V1[0].IntValue;                                    \
     789      opihi_int M2 = V2[0].IntValue;                                    \
     790      OUT[0].type = 'S';                                                \
     791      OUT[0].FltValue = OP;                                             \
     792      break;                                                            \
     793    }                                                                   \
     794    if ((V1->type == 's') && (V2->type == 's')) {                       \
     795      opihi_int M1 = V1[0].IntValue;                                    \
     796      opihi_int M2 = V2[0].IntValue;                                    \
     797      OUT[0].type = 's';                                                \
     798      OUT[0].IntValue = OP;                                             \
     799      break;                                                            \
     800    }                                                                   \
    714801  }
    715802
    716803  switch (op[0]) {
    717     case '+': SS_FUNC(M1 + M2);
    718     case '-': SS_FUNC(M1 - M2);
    719     case '*': SS_FUNC(M1 * M2);
    720     case '/': SS_FUNC(M1 / M2);
    721     case '%': SS_FUNC((int) M1 % (int) M2);
    722     case '^': SS_FUNC(pow (M1, M2));
    723     case '@': SS_FUNC(DEG_RAD*atan2 (M1, M2));
    724     case 'D': SS_FUNC(MIN (M1, M2));
    725     case 'U': SS_FUNC(MAX (M1, M2));
    726     case '<': SS_FUNC((M1 < M2) ? 1 : 0);
    727     case '>': SS_FUNC((M1 > M2) ? 1 : 0);
    728     case '&': SS_FUNC(((int)M1 & (int)M2));
    729     case '|': SS_FUNC(((int)M1 | (int)M2));
    730     case 'E': SS_FUNC((M1 == M2) ? 1 : 0);
    731     case 'N': SS_FUNC((M1 != M2) ? 1 : 0);
    732     case 'L': SS_FUNC((M1 <= M2) ? 1 : 0);
    733     case 'G': SS_FUNC((M1 >= M2) ? 1 : 0);
    734     case 'A': SS_FUNC((M1 && M2) ? 1 : 0);
    735     case 'O': SS_FUNC((M1 || M2) ? 1 : 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', (int) M1 % (int) 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', ((int)M1 & (int)M2));
     816    case '|': SS_FUNC('s', ((int)M1 | (int)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);
    736823    default:
    737824      sprintf (line, "error: op %c not defined!", op[0]);
     
    878965
    879966# define V_FUNC(OP,FTYPE) {                                     \
    880   if (V1->vector->type == OPIHI_FLT) {                          \
    881     CopyVector (OUT[0].vector, V1[0].vector);                   \
    882     opihi_flt *M1  = V1[0].vector[0].elements.Flt;              \
    883     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    884     for (i = 0; i < Nx; i++, out++, M1++) {                     \
    885       *out = OP;                                                \
     967    if (V1->vector->type == OPIHI_FLT) {                        \
     968      CopyVector (OUT[0].vector, V1[0].vector);                 \
     969      opihi_flt *M1  = V1[0].vector[0].elements.Flt;            \
     970      opihi_flt *out = OUT[0].vector[0].elements.Flt;           \
     971      for (i = 0; i < Nx; i++, out++, M1++) {                   \
     972        *out = OP;                                              \
     973      }                                                         \
     974      clear_stack (V1);                                         \
     975      return (TRUE);                                            \
    886976    }                                                           \
    887     clear_stack (V1);                                           \
    888     return (TRUE);                                              \
    889   }                                                             \
    890   if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {      \
    891     MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);       \
    892     opihi_int *M1  = V1[0].vector[0].elements.Int;              \
    893     opihi_flt *out = OUT[0].vector[0].elements.Flt;             \
    894     for (i = 0; i < Nx; i++, out++, M1++) {                     \
    895       *out = OP;                                                \
     977    if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {    \
     978      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);     \
     979      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     980      opihi_flt *out = OUT[0].vector[0].elements.Flt;           \
     981      for (i = 0; i < Nx; i++, out++, M1++) {                   \
     982        *out = OP;                                              \
     983      }                                                         \
     984      clear_stack (V1);                                         \
     985      return (TRUE);                                            \
    896986    }                                                           \
    897     clear_stack (V1);                                           \
    898     return (TRUE);                                              \
    899   }                                                             \
    900   if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {      \
    901     CopyVector (OUT[0].vector, V1[0].vector);                   \
    902     opihi_int *M1  = V1[0].vector[0].elements.Int;              \
    903     opihi_int *out = OUT[0].vector[0].elements.Int;             \
    904     for (i = 0; i < Nx; i++, out++, M1++) {                     \
    905       *out = OP;                                                \
    906     }                                                           \
    907     clear_stack (V1);                                           \
    908     return (TRUE);                                              \
    909   } }                                                   
     987    if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {    \
     988      CopyVector (OUT[0].vector, V1[0].vector);                 \
     989      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     990      opihi_int *out = OUT[0].vector[0].elements.Int;           \
     991      for (i = 0; i < Nx; i++, out++, M1++) {                   \
     992        *out = OP;                                              \
     993      }                                                         \
     994      clear_stack (V1);                                         \
     995      return (TRUE);                                            \
     996    } }                                                 
    910997
    911998  if (!strcmp (op, "="))      V_FUNC(*M1, 's');
Note: See TracChangeset for help on using the changeset viewer.