IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 7, 2008, 3:31:01 PM (17 years ago)
Author:
eugene
Message:

big update from eam_branch_20081124 with updates to Opihi math

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/dvo/dbStackMath.c

    r15718 r20936  
    44static int NallocUnary = 0;
    55
    6 dbStack *dbBinary (dbStack *V1, dbStack *V2, char *op, float *fields) {
     6dbStack *dbBinary (dbStack *V1, dbStack *V2, char *op, dbValue *fields) {
    77
    8   int N;
    9   float M1, M2;
    108  dbStack *OUT;
    119 
    12   if (V1->type == 'F') {
    13     N = V1->field;
    14     M1 = fields[N];
    15   } else {
    16     M1 = V1->Float;
    17   }
    18  
    19   if (V2->type == 'F') {
    20     N = V2->field;
    21     M2 = fields[N];
    22   } else {
    23     M2 = V2->Float;
     10# define SS_FUNC(OP) {                                                  \
     11    if (!(V1->type & DB_STACK_INT) && !(V2->type & DB_STACK_INT)) {     \
     12      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
     13      opihi_flt M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Flt : V2->FltValue; \
     14      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;                     \
     15      OUT[0].FltValue = OP;                                             \
     16      break;                                                            \
     17    }                                                                   \
     18    if ((V1->type & DB_STACK_INT) && !(V2->type & DB_STACK_INT)) {      \
     19      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
     20      opihi_flt M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Flt : V2->FltValue; \
     21      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;                     \
     22      OUT[0].FltValue = OP;                                             \
     23      break;                                                            \
     24    }                                                                   \
     25    if (!(V1->type & DB_STACK_INT) && (V2->type & DB_STACK_INT)) {      \
     26      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
     27      opihi_int M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Int : V2->IntValue; \
     28      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;                     \
     29      OUT[0].FltValue = OP;                                             \
     30      break;                                                            \
     31    }                                                                   \
     32    if ((V1->type & DB_STACK_INT) && (V2->type & DB_STACK_INT)) {       \
     33      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
     34      opihi_int M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Int : V2->IntValue; \
     35      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP | DB_STACK_INT;      \
     36      OUT[0].IntValue = OP;                                             \
     37      break;                                                            \
     38    }                                                                   \
    2439  }
    2540
    2641  NallocBinary ++;
    2742  ALLOCATE (OUT, dbStack, 1);
    28   OUT->type = 'T';
    2943  OUT->name = NULL;
    3044
    31   // use an enum for the op...
     45  // XXX use an enum for the op...
    3246  switch (op[0]) {
    33   case '+':
    34     OUT->Float = M1 + M2;
    35     break;
    36   case '-':
    37     OUT->Float = M1 - M2;
    38     break;
    39   case '*':
    40     OUT->Float = M1 * M2;
    41     break;
    42   case '/':
    43     OUT->Float = M1 / M2;
    44     break;
    45   case '%':
    46     OUT->Float = (int) M1 % (int) M2;
    47     break;
    48   case 0x5e:
    49     OUT->Float = pow (M1, M2);
    50     break;
    51   case 'D':
    52     OUT->Float = MIN (M1, M2);
    53     break;
    54   case 'U':
    55     OUT->Float = MAX (M1, M2);
    56     break;
    57   case '<':
    58     OUT->Float = (M1 < M2) ? 1 : 0;
    59     break;
    60   case '>':
    61     OUT->Float = (M1 > M2) ? 1 : 0;
    62     break;
    63   case '&':
    64     OUT->Float = ((int)M1 & (int)M2);
    65     break;
    66   case '|':
    67     OUT->Float = ((int)M1 | (int)M2);
    68     break;
    69   case 'E':
    70     OUT->Float = (M1 == M2) ? 1 : 0;
    71     break;
    72   case 'N':
    73     OUT->Float = (M1 != M2) ? 1 : 0;
    74     break;
    75   case 'L':
    76     OUT->Float = (M1 <= M2) ? 1 : 0;
    77     break;
    78   case 'G':
    79     OUT->Float = (M1 >= M2) ? 1 : 0;
    80     break;
    81   case 'A':
    82     OUT->Float = (M1 && M2) ? 1 : 0;
    83     break;
    84   case 'O':
    85     OUT->Float = (M1 || M2) ? 1 : 0;
    86     break;
     47    case '+': SS_FUNC(M1 + M2);
     48    case '-': SS_FUNC(M1 - M2);
     49    case '*': SS_FUNC(M1 * M2);
     50    case '/': SS_FUNC(M1 / M2);
     51    case '%': SS_FUNC((int) M1 % (int) M2);
     52    case '^': SS_FUNC(pow (M1, M2));
     53    case 'D': SS_FUNC(MIN (M1, M2));
     54    case 'U': SS_FUNC(MAX (M1, M2));
     55    case '<': SS_FUNC((M1 < M2) ? 1 : 0);
     56    case '>': SS_FUNC((M1 > M2) ? 1 : 0);
     57    case '&': SS_FUNC(((int)M1 & (int)M2));
     58    case '|': SS_FUNC(((int)M1 | (int)M2));
     59    case 'E': SS_FUNC((M1 == M2) ? 1 : 0);
     60    case 'N': SS_FUNC((M1 != M2) ? 1 : 0);
     61    case 'L': SS_FUNC((M1 <= M2) ? 1 : 0);
     62    case 'G': SS_FUNC((M1 >= M2) ? 1 : 0);
     63    case 'A': SS_FUNC((M1 && M2) ? 1 : 0);
     64    case 'O': SS_FUNC((M1 || M2) ? 1 : 0);
    8765  default:
    8866    return (NULL);
    8967  }
    90 
     68# undef SS_FUNC
     69 
    9170  return (OUT);
    9271}
    9372
    94 dbStack *dbUnary (dbStack *V1, char *op, float *fields) {
     73dbStack *dbUnary (dbStack *V1, char *op, dbValue *fields) {
    9574
    96   int N;
    97   float M1;
    9875  dbStack *OUT;
     76 
     77# define S_FUNC(OP,FTYPE) {                                             \
     78    if (!(V1->type & DB_STACK_INT)) {                                   \
     79      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
     80      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;                     \
     81      OUT[0].FltValue = OP;                                             \
     82      return (OUT);                                                     \
     83    }                                                                   \
     84    if ((FTYPE != DB_STACK_INT) && (V1->type & DB_STACK_INT)) {         \
     85      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
     86      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;                     \
     87      OUT[0].FltValue = OP;                                             \
     88      return (OUT);                                                     \
     89    }                                                                   \
     90    if ((FTYPE == DB_STACK_INT) && (V1->type & DB_STACK_INT)) {         \
     91      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
     92      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP | DB_STACK_INT;      \
     93      OUT[0].IntValue = OP;                                             \
     94      return (OUT);                                                     \
     95    }                                                                   \
     96  }
    9997
    100   if (V1->type == 'F') {
    101     N = V1->field;
    102     M1 = fields[N];
    103   } else {
    104     M1 = V1->Float;
    105   }
    106  
    10798  NallocUnary ++;
    10899  ALLOCATE (OUT, dbStack, 1);
    109   OUT->type = 'T';
    110100  OUT->name = NULL;
    111101
    112   if (!strcmp (op, "="))      {   OUT->Float = M1;                 }
    113   if (!strcmp (op, "abs"))    {   OUT->Float = fabs(M1);           }
    114   if (!strcmp (op, "int"))    {   OUT->Float = (float)(int)(M1);   }
    115   if (!strcmp (op, "exp"))    {   OUT->Float = exp (M1);           }
    116   if (!strcmp (op, "ten"))    {   OUT->Float = pow (10.0,M1);      }
    117   if (!strcmp (op, "log"))    {   OUT->Float = log10 (M1);         }
    118   if (!strcmp (op, "ln"))     {   OUT->Float = log (M1);           }
    119   if (!strcmp (op, "sqrt"))   {   OUT->Float = sqrt (M1);          }
    120   if (!strcmp (op, "erf"))    {   OUT->Float = erf (M1);           }
    121                                                      
    122   if (!strcmp (op, "sinh"))   {   OUT->Float = sinh (M1);          }
    123   if (!strcmp (op, "cosh"))   {   OUT->Float = cosh (M1);          }
    124   if (!strcmp (op, "asinh"))  {   OUT->Float = asinh (M1);         }
    125   if (!strcmp (op, "acosh"))  {   OUT->Float = acosh (M1);         }
    126   if (!strcmp (op, "lgamma")) {   OUT->Float = lgamma (M1);        }
     102  if (!strcmp (op, "="))      S_FUNC(M1,0);
     103  if (!strcmp (op, "abs"))    S_FUNC(fabs(M1),0);
     104  if (!strcmp (op, "int"))    S_FUNC((int)(M1),DB_STACK_INT);
     105  if (!strcmp (op, "exp"))    S_FUNC(exp (M1),0);
     106  if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1),0);
     107  if (!strcmp (op, "log"))    S_FUNC(log10 (M1),0);
     108  if (!strcmp (op, "ln"))     S_FUNC(log (M1),0);
     109  if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1),0);
     110  if (!strcmp (op, "erf"))    S_FUNC(erf (M1),0);
    127111
    128   if (!strcmp (op, "sin"))    {   OUT->Float = sin (M1);           }
    129   if (!strcmp (op, "cos"))    {   OUT->Float = cos (M1);           }
    130   if (!strcmp (op, "tan"))    {   OUT->Float = tan (M1);           }
    131   if (!strcmp (op, "dsin"))   {   OUT->Float = sin (M1*RAD_DEG);   }
    132   if (!strcmp (op, "dcos"))   {   OUT->Float = cos (M1*RAD_DEG);   }
    133   if (!strcmp (op, "dtan"))   {   OUT->Float = tan (M1*RAD_DEG);   }
    134   if (!strcmp (op, "asin"))   {   OUT->Float = asin (M1);          }
    135   if (!strcmp (op, "acos"))   {   OUT->Float = acos (M1);          }
    136   if (!strcmp (op, "atan"))   {   OUT->Float = atan (M1);          }
    137   if (!strcmp (op, "dasin"))  {   OUT->Float = asin (M1)*DEG_RAD;  }
    138   if (!strcmp (op, "dacos"))  {   OUT->Float = acos (M1)*DEG_RAD;  }
    139   if (!strcmp (op, "datan"))  {   OUT->Float = atan (M1)*DEG_RAD;  }
    140   if (!strcmp (op, "rnd"))    {   OUT->Float = drand48();          }
    141   if (!strcmp (op, "not"))    {   OUT->Float = !(M1);              }
    142   if (!strcmp (op, "--"))     {   OUT->Float = - (M1);             }
    143   if (!strcmp (op, "isinf"))  {   OUT->Float = !finite(M1);        }
    144   if (!strcmp (op, "isnan"))  {   OUT->Float = isnan(M1);          }
     112  if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1),0);
     113  if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1),0);
     114  if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1),0);
     115  if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1),0);
     116  if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1),0);
     117
     118  if (!strcmp (op, "sin"))    S_FUNC(sin (M1),0);
     119  if (!strcmp (op, "cos"))    S_FUNC(cos (M1),0);
     120  if (!strcmp (op, "tan"))    S_FUNC(tan (M1),0);
     121  if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG),0);
     122  if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG),0);
     123  if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG),0);
     124  if (!strcmp (op, "asin"))   S_FUNC(asin (M1),0);
     125  if (!strcmp (op, "acos"))   S_FUNC(acos (M1),0);
     126  if (!strcmp (op, "atan"))   S_FUNC(atan (M1),0);
     127  if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD,0);
     128  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD,0);
     129  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD,0);
     130  if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(),0);
     131  if (!strcmp (op, "not"))    S_FUNC(!(M1),DB_STACK_INT);
     132  if (!strcmp (op, "--"))     S_FUNC(- (M1),DB_STACK_INT);
     133  if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1),DB_STACK_INT);
     134  if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1),DB_STACK_INT);
    145135
    146136  return (OUT);
Note: See TracChangeset for help on using the changeset viewer.