Index: trunk/Ohana/src/opihi/dvo/dbStackMath.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/dbStackMath.c	(revision 15718)
+++ trunk/Ohana/src/opihi/dvo/dbStackMath.c	(revision 20936)
@@ -4,143 +4,133 @@
 static int NallocUnary = 0;
 
-dbStack *dbBinary (dbStack *V1, dbStack *V2, char *op, float *fields) {
+dbStack *dbBinary (dbStack *V1, dbStack *V2, char *op, dbValue *fields) {
 
-  int N;
-  float M1, M2;
   dbStack *OUT;
   
-  if (V1->type == 'F') {
-    N = V1->field;
-    M1 = fields[N];
-  } else {
-    M1 = V1->Float;
-  }
-  
-  if (V2->type == 'F') {
-    N = V2->field;
-    M2 = fields[N];
-  } else {
-    M2 = V2->Float;
+# define SS_FUNC(OP) {							\
+    if (!(V1->type & DB_STACK_INT) && !(V2->type & DB_STACK_INT)) {	\
+      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
+      opihi_flt M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Flt : V2->FltValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((V1->type & DB_STACK_INT) && !(V2->type & DB_STACK_INT)) {	\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      opihi_flt M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Flt : V2->FltValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if (!(V1->type & DB_STACK_INT) && (V2->type & DB_STACK_INT)) {	\
+      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
+      opihi_int M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Int : V2->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((V1->type & DB_STACK_INT) && (V2->type & DB_STACK_INT)) {	\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      opihi_int M2 = (V2->type & DB_STACK_FIELD) ? fields[V2->field].Int : V2->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP | DB_STACK_INT;	\
+      OUT[0].IntValue = OP;						\
+      break;								\
+    }									\
   }
 
   NallocBinary ++;
   ALLOCATE (OUT, dbStack, 1);
-  OUT->type = 'T';
   OUT->name = NULL;
 
-  // use an enum for the op...
+  // XXX use an enum for the op...
   switch (op[0]) { 
-  case '+': 
-    OUT->Float = M1 + M2;
-    break; 
-  case '-': 
-    OUT->Float = M1 - M2;
-    break; 
-  case '*': 
-    OUT->Float = M1 * M2;
-    break; 
-  case '/': 
-    OUT->Float = M1 / M2;
-    break; 
-  case '%': 
-    OUT->Float = (int) M1 % (int) M2;
-    break; 
-  case 0x5e: 
-    OUT->Float = pow (M1, M2);
-    break; 
-  case 'D': 
-    OUT->Float = MIN (M1, M2);
-    break; 
-  case 'U': 
-    OUT->Float = MAX (M1, M2);
-    break; 
-  case '<': 
-    OUT->Float = (M1 < M2) ? 1 : 0;
-    break; 
-  case '>': 
-    OUT->Float = (M1 > M2) ? 1 : 0;
-    break; 
-  case '&': 
-    OUT->Float = ((int)M1 & (int)M2);
-    break; 
-  case '|': 
-    OUT->Float = ((int)M1 | (int)M2);
-    break; 
-  case 'E': 
-    OUT->Float = (M1 == M2) ? 1 : 0;
-    break; 
-  case 'N': 
-    OUT->Float = (M1 != M2) ? 1 : 0;
-    break; 
-  case 'L': 
-    OUT->Float = (M1 <= M2) ? 1 : 0;
-    break; 
-  case 'G': 
-    OUT->Float = (M1 >= M2) ? 1 : 0;
-    break; 
-  case 'A': 
-    OUT->Float = (M1 && M2) ? 1 : 0;
-    break; 
-  case 'O': 
-    OUT->Float = (M1 || M2) ? 1 : 0;
-    break; 
+    case '+': SS_FUNC(M1 + M2);
+    case '-': SS_FUNC(M1 - M2);
+    case '*': SS_FUNC(M1 * M2);
+    case '/': SS_FUNC(M1 / M2);
+    case '%': SS_FUNC((int) M1 % (int) M2);
+    case '^': SS_FUNC(pow (M1, M2));
+    case 'D': SS_FUNC(MIN (M1, M2));
+    case 'U': SS_FUNC(MAX (M1, M2));
+    case '<': SS_FUNC((M1 < M2) ? 1 : 0);
+    case '>': SS_FUNC((M1 > M2) ? 1 : 0);
+    case '&': SS_FUNC(((int)M1 & (int)M2));
+    case '|': SS_FUNC(((int)M1 | (int)M2));
+    case 'E': SS_FUNC((M1 == M2) ? 1 : 0);
+    case 'N': SS_FUNC((M1 != M2) ? 1 : 0);
+    case 'L': SS_FUNC((M1 <= M2) ? 1 : 0);
+    case 'G': SS_FUNC((M1 >= M2) ? 1 : 0);
+    case 'A': SS_FUNC((M1 && M2) ? 1 : 0);
+    case 'O': SS_FUNC((M1 || M2) ? 1 : 0);
   default:
     return (NULL);
   }
-
+# undef SS_FUNC
+  
   return (OUT);
 }
 
-dbStack *dbUnary (dbStack *V1, char *op, float *fields) {
+dbStack *dbUnary (dbStack *V1, char *op, dbValue *fields) {
 
-  int N;
-  float M1;
   dbStack *OUT;
+  
+# define S_FUNC(OP,FTYPE) {						\
+    if (!(V1->type & DB_STACK_INT)) {					\
+      opihi_flt M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Flt : V1->FltValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      return (OUT);							\
+    }									\
+    if ((FTYPE != DB_STACK_INT) && (V1->type & DB_STACK_INT)) {		\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP;			\
+      OUT[0].FltValue = OP;						\
+      return (OUT);							\
+    }									\
+    if ((FTYPE == DB_STACK_INT) && (V1->type & DB_STACK_INT)) {		\
+      opihi_int M1 = (V1->type & DB_STACK_FIELD) ? fields[V1->field].Int : V1->IntValue; \
+      OUT[0].type = DB_STACK_VALUE | DB_STACK_TEMP | DB_STACK_INT;	\
+      OUT[0].IntValue = OP;						\
+      return (OUT);							\
+    }									\
+  }
 
-  if (V1->type == 'F') {
-    N = V1->field;
-    M1 = fields[N];
-  } else {
-    M1 = V1->Float;
-  }
-  
   NallocUnary ++;
   ALLOCATE (OUT, dbStack, 1);
-  OUT->type = 'T';
   OUT->name = NULL;
 
-  if (!strcmp (op, "="))      {   OUT->Float = M1;                 }
-  if (!strcmp (op, "abs"))    {   OUT->Float = fabs(M1);           }
-  if (!strcmp (op, "int"))    {   OUT->Float = (float)(int)(M1);   }
-  if (!strcmp (op, "exp"))    {   OUT->Float = exp (M1);           }
-  if (!strcmp (op, "ten"))    {   OUT->Float = pow (10.0,M1);      }
-  if (!strcmp (op, "log"))    {   OUT->Float = log10 (M1);         }
-  if (!strcmp (op, "ln"))     {   OUT->Float = log (M1);           }
-  if (!strcmp (op, "sqrt"))   {   OUT->Float = sqrt (M1);          }
-  if (!strcmp (op, "erf"))    {   OUT->Float = erf (M1);           }
-			      			      
-  if (!strcmp (op, "sinh"))   {   OUT->Float = sinh (M1);          }
-  if (!strcmp (op, "cosh"))   {   OUT->Float = cosh (M1);          }
-  if (!strcmp (op, "asinh"))  {   OUT->Float = asinh (M1);         }
-  if (!strcmp (op, "acosh"))  {   OUT->Float = acosh (M1);         }
-  if (!strcmp (op, "lgamma")) {   OUT->Float = lgamma (M1);        }
+  if (!strcmp (op, "="))      S_FUNC(M1,0);
+  if (!strcmp (op, "abs"))    S_FUNC(fabs(M1),0);
+  if (!strcmp (op, "int"))    S_FUNC((int)(M1),DB_STACK_INT);
+  if (!strcmp (op, "exp"))    S_FUNC(exp (M1),0);
+  if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1),0);
+  if (!strcmp (op, "log"))    S_FUNC(log10 (M1),0);
+  if (!strcmp (op, "ln"))     S_FUNC(log (M1),0);
+  if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1),0);
+  if (!strcmp (op, "erf"))    S_FUNC(erf (M1),0);
 
-  if (!strcmp (op, "sin"))    {   OUT->Float = sin (M1);           }
-  if (!strcmp (op, "cos"))    {   OUT->Float = cos (M1);           }
-  if (!strcmp (op, "tan"))    {   OUT->Float = tan (M1);           }
-  if (!strcmp (op, "dsin"))   {   OUT->Float = sin (M1*RAD_DEG);   }
-  if (!strcmp (op, "dcos"))   {   OUT->Float = cos (M1*RAD_DEG);   }
-  if (!strcmp (op, "dtan"))   {   OUT->Float = tan (M1*RAD_DEG);   }
-  if (!strcmp (op, "asin"))   {   OUT->Float = asin (M1);          }
-  if (!strcmp (op, "acos"))   {   OUT->Float = acos (M1);          }
-  if (!strcmp (op, "atan"))   {   OUT->Float = atan (M1);          }
-  if (!strcmp (op, "dasin"))  {   OUT->Float = asin (M1)*DEG_RAD;  }
-  if (!strcmp (op, "dacos"))  {   OUT->Float = acos (M1)*DEG_RAD;  }
-  if (!strcmp (op, "datan"))  {   OUT->Float = atan (M1)*DEG_RAD;  }
-  if (!strcmp (op, "rnd"))    {   OUT->Float = drand48();          }
-  if (!strcmp (op, "not"))    {   OUT->Float = !(M1);              }
-  if (!strcmp (op, "--"))     {   OUT->Float = - (M1);             }
-  if (!strcmp (op, "isinf"))  {   OUT->Float = !finite(M1);        }
-  if (!strcmp (op, "isnan"))  {   OUT->Float = isnan(M1);          } 
+  if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1),0);
+  if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1),0);
+  if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1),0);
+  if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1),0);
+  if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1),0);
+
+  if (!strcmp (op, "sin"))    S_FUNC(sin (M1),0);
+  if (!strcmp (op, "cos"))    S_FUNC(cos (M1),0);
+  if (!strcmp (op, "tan"))    S_FUNC(tan (M1),0);
+  if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG),0);
+  if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG),0);
+  if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG),0);
+  if (!strcmp (op, "asin"))   S_FUNC(asin (M1),0);
+  if (!strcmp (op, "acos"))   S_FUNC(acos (M1),0);
+  if (!strcmp (op, "atan"))   S_FUNC(atan (M1),0);
+  if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD,0);
+  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD,0);
+  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD,0);
+  if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(),0);
+  if (!strcmp (op, "not"))    S_FUNC(!(M1),DB_STACK_INT);
+  if (!strcmp (op, "--"))     S_FUNC(- (M1),DB_STACK_INT);
+  if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1),DB_STACK_INT);
+  if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1),DB_STACK_INT);
 
   return (OUT);
