Index: /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c
===================================================================
--- /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c	(revision 20911)
+++ /branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c	(revision 20912)
@@ -28,5 +28,5 @@
   // set up the possible operations : int OP int -> int, all else yield float
   // OP is the operation performed on *M1 and *M2
-# define VV_FUNC(OP) {							\
+# define VV_FUNC(FTYPE,OP) {						\
     if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V1[0].vector);				\
@@ -59,4 +59,14 @@
       break;								\
     }									\
+    if ((FTYPE == 'S') && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
+      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);		\
+      opihi_int *M1  =  V1[0].vector[0].elements.Int;			\
+      opihi_int *M2  =  V2[0].vector[0].elements.Int;			\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M1++, M2++) {			\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
     if ((V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
       CopyVector (OUT[0].vector, V1[0].vector);				\
@@ -65,29 +75,30 @@
       opihi_int *out = OUT[0].vector[0].elements.Int;			\
       for (i = 0; i < Nx; i++, out++, M1++, M2++) {			\
-  	*out = OP;							\
-      }									\
-      break;								\
-    } }
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+  }
 
   switch (op[0]) {
-    case '+': VV_FUNC(*M1 + *M2);
-    case '-': VV_FUNC(*M1 - *M2);
-    case '*': VV_FUNC(*M1 * *M2);
-    case '/': VV_FUNC(*M1 / *M2);
-    case '%': VV_FUNC((int)*M1 % (int)*M2);
-    case '^': VV_FUNC(pow (*M1, *M2));
-    case '@': VV_FUNC(DEG_RAD*atan2 (*M1, *M2));
-    case 'D': VV_FUNC(MIN (*M1, *M2));
-    case 'U': VV_FUNC(MAX (*M1, *M2));
-    case '<': VV_FUNC((*M1 < *M2) ? 1 : 0);
-    case '>': VV_FUNC((*M1 > *M2) ? 1 : 0);
-    case '&': VV_FUNC(((int)*M1 & (int)*M2));
-    case '|': VV_FUNC(((int)*M1 | (int)*M2));
-    case 'E': VV_FUNC((*M1 == *M2) ? 1 : 0);
-    case 'N': VV_FUNC((*M1 != *M2) ? 1 : 0);
-    case 'L': VV_FUNC((*M1 <= *M2) ? 1 : 0);
-    case 'G': VV_FUNC((*M1 >= *M2) ? 1 : 0);
-    case 'A': VV_FUNC((*M1 && *M2) ? 1 : 0);
-    case 'O': VV_FUNC((*M1 || *M2) ? 1 : 0);
+    case '+': VV_FUNC('s', *M1 + *M2);
+    case '-': VV_FUNC('s', *M1 - *M2);
+    case '*': VV_FUNC('s', *M1 * *M2);
+    case '/': VV_FUNC('S', *M1 / (opihi_flt) *M2);
+    case '%': VV_FUNC('s', (int)*M1 % (int)*M2);
+    case '^': VV_FUNC('S', pow (*M1, *M2));
+    case '@': VV_FUNC('S', DEG_RAD*atan2 (*M1, *M2));
+    case 'D': VV_FUNC('s', MIN (*M1, *M2));
+    case 'U': VV_FUNC('s', MAX (*M1, *M2));
+    case '<': VV_FUNC('s', (*M1 < *M2) ? 1 : 0);
+    case '>': VV_FUNC('s', (*M1 > *M2) ? 1 : 0);
+    case '&': VV_FUNC('s', ((int)*M1 & (int)*M2));
+    case '|': VV_FUNC('s', ((int)*M1 | (int)*M2));
+    case 'E': VV_FUNC('s', (*M1 == *M2) ? 1 : 0);
+    case 'N': VV_FUNC('s', (*M1 != *M2) ? 1 : 0);
+    case 'L': VV_FUNC('s', (*M1 <= *M2) ? 1 : 0);
+    case 'G': VV_FUNC('s', (*M1 >= *M2) ? 1 : 0);
+    case 'A': VV_FUNC('s', (*M1 && *M2) ? 1 : 0);
+    case 'O': VV_FUNC('s', (*M1 || *M2) ? 1 : 0);
     default:
       sprintf (line, "error: op %c not defined!", op[0]);
@@ -127,66 +138,77 @@
   // set up the possible operations : int OP int -> int, all else yield float
   // OP is the operation performed on *M1 and *M2
-# define SV_FUNC(OP)						\
-  if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) {	\
-    CopyVector (OUT[0].vector, V2[0].vector);			\
-    opihi_flt  M1  =  V1[0].FltValue;				\
-    opihi_flt *M2  =  V2[0].vector[0].elements.Flt;		\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M2++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
-  }								\
-  if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) {	\
-    MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);	\
-    opihi_flt  M1  =  V1[0].FltValue;				\
-    opihi_int *M2  =  V2[0].vector[0].elements.Int;		\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M2++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
-  }								\
-  if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) {	\
-    CopyVector (OUT[0].vector, V2[0].vector);			\
-    opihi_int  M1  =  V1[0].IntValue;				\
-    opihi_flt *M2  =  V2[0].vector[0].elements.Flt;		\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M2++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
-  }								\
-  if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) {	\
-    CopyVector (OUT[0].vector, V2[0].vector);			\
-    opihi_int  M1  =  V1[0].IntValue;				\
-    opihi_int *M2  =  V2[0].vector[0].elements.Int;		\
-    opihi_int *out = OUT[0].vector[0].elements.Int;		\
-    for (i = 0; i < Nx; i++, out++, M2++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
+# define SV_FUNC(FTYPE,OP) {						\
+    if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) {		\
+      CopyVector (OUT[0].vector, V2[0].vector);				\
+      opihi_flt  M1  =  V1[0].FltValue;					\
+      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;			\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M2++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) {		\
+      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);		\
+      opihi_flt  M1  =  V1[0].FltValue;					\
+      opihi_int *M2  =  V2[0].vector[0].elements.Int;			\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M2++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) {		\
+      CopyVector (OUT[0].vector, V2[0].vector);				\
+      opihi_int  M1  =  V1[0].IntValue;					\
+      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;			\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M2++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((FTYPE == 'S') && (V1->type == 's') && (V2->vector->type != OPIHI_FLT)) { \
+      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);		\
+      opihi_int  M1  =  V1[0].IntValue;					\
+      opihi_int *M2  =  V2[0].vector[0].elements.Int;			\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M2++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) {		\
+      CopyVector (OUT[0].vector, V2[0].vector);				\
+      opihi_int  M1  =  V1[0].IntValue;					\
+      opihi_int *M2  =  V2[0].vector[0].elements.Int;			\
+      opihi_int *out = OUT[0].vector[0].elements.Int;			\
+      for (i = 0; i < Nx; i++, out++, M2++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
   }
 
   switch (op[0]) { 
-    case '+': SV_FUNC(M1 + *M2);
-    case '-': SV_FUNC(M1 - *M2);
-    case '*': SV_FUNC(M1 * *M2);
-    case '/': SV_FUNC(M1 / *M2);
-    case '%': SV_FUNC((int) M1 % (int) *M2);
-    case '^': SV_FUNC(pow (M1, *M2));
-    case '@': SV_FUNC(DEG_RAD*atan2 (M1, *M2));
-    case 'D': SV_FUNC(MIN (M1, *M2));
-    case 'U': SV_FUNC(MAX (M1, *M2));
-    case '<': SV_FUNC((M1 < *M2) ? 1 : 0);
-    case '>': SV_FUNC((M1 > *M2) ? 1 : 0);
-    case '&': SV_FUNC(((int)M1 & (int)*M2));
-    case '|': SV_FUNC(((int)M1 | (int)*M2));
-    case 'E': SV_FUNC((M1 == *M2) ? 1 : 0);
-    case 'N': SV_FUNC((M1 != *M2) ? 1 : 0);
-    case 'L': SV_FUNC((M1 <= *M2) ? 1 : 0);
-    case 'G': SV_FUNC((M1 >= *M2) ? 1 : 0);
-    case 'A': SV_FUNC((M1 && *M2) ? 1 : 0);
-    case 'O': SV_FUNC((M1 || *M2) ? 1 : 0);
+    case '+': SV_FUNC('s', M1 + *M2);
+    case '-': SV_FUNC('s', M1 - *M2);
+    case '*': SV_FUNC('s', M1 * *M2);
+    case '/': SV_FUNC('S', M1 / (opihi_flt) *M2);
+    case '%': SV_FUNC('s', (int) M1 % (int) *M2);
+    case '^': SV_FUNC('S', pow (M1, *M2));
+    case '@': SV_FUNC('S', DEG_RAD*atan2 (M1, *M2));
+    case 'D': SV_FUNC('s', MIN (M1, *M2));
+    case 'U': SV_FUNC('s', MAX (M1, *M2));
+    case '<': SV_FUNC('s', (M1 < *M2) ? 1 : 0);
+    case '>': SV_FUNC('s', (M1 > *M2) ? 1 : 0);
+    case '&': SV_FUNC('s', ((int)M1 & (int)*M2));
+    case '|': SV_FUNC('s', ((int)M1 | (int)*M2));
+    case 'E': SV_FUNC('s', (M1 == *M2) ? 1 : 0);
+    case 'N': SV_FUNC('s', (M1 != *M2) ? 1 : 0);
+    case 'L': SV_FUNC('s', (M1 <= *M2) ? 1 : 0);
+    case 'G': SV_FUNC('s', (M1 >= *M2) ? 1 : 0);
+    case 'A': SV_FUNC('s', (M1 && *M2) ? 1 : 0);
+    case 'O': SV_FUNC('s', (M1 || *M2) ? 1 : 0);
     default:
       sprintf (line, "error: op %c not defined!", op[0]);
@@ -222,66 +244,77 @@
   // set up the possible operations : int OP int -> int, all else yield float
   // OP is the operation performed on *M1 and *M2
-# define VS_FUNC(OP)						\
-  if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) {	\
-    CopyVector (OUT[0].vector, V1[0].vector);			\
-    opihi_flt *M1  =  V1[0].vector[0].elements.Flt;		\
-    opihi_flt  M2  =  V2[0].FltValue;				\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M1++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
-  }								\
-  if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) {	\
-    MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);	\
-    opihi_int *M1  =  V1[0].vector[0].elements.Int;		\
-    opihi_flt  M2  =  V2[0].FltValue;				\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M1++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
-  }								\
-  if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) {	\
-    CopyVector (OUT[0].vector, V1[0].vector);			\
-    opihi_flt *M1  =  V1[0].vector[0].elements.Flt;		\
-    opihi_int  M2  =  V2[0].IntValue;				\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M1++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
-  }								\
-  if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) {	\
-    CopyVector (OUT[0].vector, V1[0].vector);			\
-    opihi_int *M1  =  V1[0].vector[0].elements.Int;		\
-    opihi_int  M2  =  V2[0].IntValue;				\
-    opihi_int *out = OUT[0].vector[0].elements.Int;		\
-    for (i = 0; i < Nx; i++, out++, M1++) {			\
-      *out = OP;						\
-    }								\
-    break;							\
+# define VS_FUNC(FTYPE,OP) {						\
+    if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) {		\
+      CopyVector (OUT[0].vector, V1[0].vector);				\
+      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;			\
+      opihi_flt  M2  =  V2[0].FltValue;					\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) {		\
+      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);		\
+      opihi_int *M1  =  V1[0].vector[0].elements.Int;			\
+      opihi_flt  M2  =  V2[0].FltValue;					\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) {		\
+      CopyVector (OUT[0].vector, V1[0].vector);				\
+      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;			\
+      opihi_int  M2  =  V2[0].IntValue;					\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((FTYPE == 'S') && (V2->type == 's') && (V1->vector->type != OPIHI_FLT)) { \
+      CopyVector (OUT[0].vector, V1[0].vector);				\
+      opihi_int *M1  =  V1[0].vector[0].elements.Int;			\
+      opihi_int  M2  =  V2[0].IntValue;					\
+      opihi_int *out = OUT[0].vector[0].elements.Int;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
+    if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) {		\
+      CopyVector (OUT[0].vector, V1[0].vector);				\
+      opihi_int *M1  =  V1[0].vector[0].elements.Int;			\
+      opihi_int  M2  =  V2[0].IntValue;					\
+      opihi_int *out = OUT[0].vector[0].elements.Int;			\
+      for (i = 0; i < Nx; i++, out++, M1++) {				\
+	*out = OP;							\
+      }									\
+      break;								\
+    }									\
   }
 
   switch (op[0]) { 
-    case '+': VS_FUNC(*M1 + M2);
-    case '-': VS_FUNC(*M1 - M2);
-    case '*': VS_FUNC(*M1 * M2);
-    case '/': VS_FUNC(*M1 / M2);
-    case '%': VS_FUNC((int) *M1 % (int) M2);
-    case '^': VS_FUNC(pow (*M1, M2));
-    case '@': VS_FUNC(DEG_RAD*atan2 (*M1, M2));
-    case 'D': VS_FUNC(MIN (*M1, M2));
-    case 'U': VS_FUNC(MAX (*M1, M2));
-    case '<': VS_FUNC((*M1 < M2) ? 1 : 0);
-    case '>': VS_FUNC((*M1 > M2) ? 1 : 0);
-    case '&': VS_FUNC(((int)*M1 & (int)M2));
-    case '|': VS_FUNC(((int)*M1 | (int)M2));
-    case 'E': VS_FUNC((*M1 == M2) ? 1 : 0);
-    case 'N': VS_FUNC((*M1 != M2) ? 1 : 0);
-    case 'L': VS_FUNC((*M1 <= M2) ? 1 : 0);
-    case 'G': VS_FUNC((*M1 >= M2) ? 1 : 0);
-    case 'A': VS_FUNC((*M1 && M2) ? 1 : 0);
-    case 'O': VS_FUNC((*M1 || M2) ? 1 : 0);
+    case '+': VS_FUNC('s', *M1 + M2);
+    case '-': VS_FUNC('s', *M1 - M2);
+    case '*': VS_FUNC('s', *M1 * M2);
+    case '/': VS_FUNC('S', *M1 / (opihi_flt) M2);
+    case '%': VS_FUNC('s', (int) *M1 % (int) M2);
+    case '^': VS_FUNC('S', pow (*M1, M2));
+    case '@': VS_FUNC('S', DEG_RAD*atan2 (*M1, M2));
+    case 'D': VS_FUNC('s', MIN (*M1, M2));
+    case 'U': VS_FUNC('s', MAX (*M1, M2));
+    case '<': VS_FUNC('s', (*M1 < M2) ? 1 : 0);
+    case '>': VS_FUNC('s', (*M1 > M2) ? 1 : 0);
+    case '&': VS_FUNC('s', ((int)*M1 & (int)M2));
+    case '|': VS_FUNC('s', ((int)*M1 | (int)M2));
+    case 'E': VS_FUNC('s', (*M1 == M2) ? 1 : 0);
+    case 'N': VS_FUNC('s', (*M1 != M2) ? 1 : 0);
+    case 'L': VS_FUNC('s', (*M1 <= M2) ? 1 : 0);
+    case 'G': VS_FUNC('s', (*M1 >= M2) ? 1 : 0);
+    case 'A': VS_FUNC('s', (*M1 && M2) ? 1 : 0);
+    case 'O': VS_FUNC('s', (*M1 || M2) ? 1 : 0);
     default:
       sprintf (line, "error: op %c not defined!", op[0]);
@@ -331,14 +364,26 @@
 
   float     *M1  = (float *) V1[0].buffer[0].matrix.buffer;
-  opihi_flt *M2  = V2[0].vector[0].elements.Flt;
   float     *out = (float *)OUT[0].buffer[0].matrix.buffer;
 
-# define MV_FUNC(OP)				\
-  for (i = 0; i < Ny; i++, M2++) {		\
-    for (j = 0; j < Nx; j++, out++, M1++) {	\
-      *out = OP;				\
-    }						\
-  }						\
-  break; 
+# define MV_FUNC(OP) {					\
+    if (V2->vector->type == OPIHI_FLT) {		\
+      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;	\
+      for (i = 0; i < Ny; i++, M2++) {			\
+	for (j = 0; j < Nx; j++, out++, M1++) {		\
+	  *out = OP;					\
+	}						\
+      }							\
+      break;						\
+    }							\
+    if (V2->vector->type != OPIHI_FLT) {		\
+      opihi_int *M2  =  V2[0].vector[0].elements.Int;	\
+      for (i = 0; i < Ny; i++, M2++) {			\
+	for (j = 0; j < Nx; j++, out++, M1++) {		\
+	  *out = OP;					\
+	}						\
+      }							\
+      break;						\
+    }							\
+  }
 
   switch (op[0]) { 
@@ -346,5 +391,5 @@
     case '-': MV_FUNC(*M1 - *M2);
     case '*': MV_FUNC(*M1 * *M2);
-    case '/': MV_FUNC(*M1 / *M2);
+    case '/': MV_FUNC(*M1 / (opihi_flt) *M2);
     case '%': MV_FUNC((int) *M1 % (int) *M2);
     case '^': MV_FUNC(pow (*M1, *M2));
@@ -367,4 +412,5 @@
       return (FALSE);
   }
+# undef MV_FUNC
 
   /** free up any temporary buffers: **/
@@ -409,16 +455,27 @@
   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
 
-  opihi_flt *M1  = V1[0].vector[0].elements.Flt;
   float     *M2  = (float *) V2[0].buffer[0].matrix.buffer;
   float     *out = (float *)OUT[0].buffer[0].matrix.buffer;
 
-# define VM_FUNC(OP)					\
-  for (i = 0; i < Ny; i++) {				\
-    M1  = V1[0].vector[0].elements.Flt;			\
-    for (j = 0; j < Nx; j++, out++, M1++, M2++) {	\
-      *out = OP;					\
+# define VM_FUNC(OP) {					\
+    if (V1->vector->type == OPIHI_FLT) {		\
+      for (i = 0; i < Ny; i++) {			\
+	opihi_flt *M1  = V1[0].vector[0].elements.Flt;	\
+	for (j = 0; j < Nx; j++, out++, M1++, M2++) {	\
+	  *out = OP;					\
+	}						\
+      }							\
+      break;						\
     }							\
-  }							\
-  break; 
+    if (V1->vector->type != OPIHI_FLT) {		\
+      for (i = 0; i < Ny; i++) {			\
+	opihi_int *M1  =  V1[0].vector[0].elements.Int;	\
+	for (j = 0; j < Nx; j++, out++, M1++, M2++) {	\
+	  *out = OP;					\
+	}						\
+      }							\
+      break;						\
+    }							\
+  }
 
   switch (op[0]) { 
@@ -426,5 +483,5 @@
     case '-': VM_FUNC(*M1 - *M2);
     case '*': VM_FUNC(*M1 * *M2);
-    case '/': VM_FUNC(*M1 / *M2);
+    case '/': VM_FUNC(*M1 / (opihi_flt) *M2);
     case '%': VM_FUNC((int) *M1 % (int) *M2);
     case '^': VM_FUNC(pow (*M1, *M2));
@@ -447,4 +504,5 @@
       return (FALSE);
   }
+# undef VM_FUNC
 
   /** free up any temporary buffers: **/
@@ -505,5 +563,5 @@
     case '-': MM_FUNC(*M1 - *M2);
     case '*': MM_FUNC(*M1 * *M2);
-    case '/': MM_FUNC(*M1 / *M2);
+    case '/': MM_FUNC(*M1 / (float) *M2);
     case '%': MM_FUNC((int) *M1 % (int) *M2);
     case '^': MM_FUNC(pow (*M1, *M2));
@@ -567,12 +625,22 @@
 
   float *M1    = (float *)V1[0].buffer[0].matrix.buffer;
-  opihi_flt M2 = V2[0].FltValue;
   float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
 
-# define MS_FUNC(OP)				\
-  for (i = 0; i < Nx*Ny; i++, out++, M1++) {	\
-    *out = OP;					\
-  }						\
-  break; 
+# define MS_FUNC(OP) {					\
+    if (V2->type == 's')  {				\
+      opihi_flt M2 = V2[0].FltValue;			\
+      for (i = 0; i < Nx*Ny; i++, out++, M1++) {	\
+	*out = OP;					\
+      }							\
+      break;						\
+    }							\
+    if (V2->type == 'S')  {				\
+      opihi_int M2 = V2[0].IntValue;			\
+      for (i = 0; i < Nx*Ny; i++, out++, M1++) {	\
+	*out = OP;					\
+      }							\
+      break;						\
+    }							\
+  }
 
   switch (op[0]) { 
@@ -580,5 +648,5 @@
     case '-': MS_FUNC(*M1 - M2);
     case '*': MS_FUNC(*M1 * M2);
-    case '/': MS_FUNC(*M1 / M2);
+    case '/': MS_FUNC(*M1 / (float) M2);
     case '%': MS_FUNC((int) *M1 % (int) M2);
     case '^': MS_FUNC(pow (*M1, M2));
@@ -632,12 +700,23 @@
   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
 
-  opihi_flt M1 = V1[0].FltValue;
   float *M2    = (float *)V2[0].buffer[0].matrix.buffer;
   float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
 
-# define SM_FUNC(OP)				\
-  for (i = 0; i < Nx*Ny; i++, out++, M2++)	\
-    *out = OP;					\
-  break; 
+# define SM_FUNC(OP) {					\
+    if (V1->type == 's')  {				\
+      opihi_flt M1 = V1[0].FltValue;			\
+      for (i = 0; i < Nx*Ny; i++, out++, M2++) {	\
+	*out = OP;					\
+      }							\
+      break;						\
+    }							\
+    if (V1->type == 'S')  {				\
+      opihi_int M1 = V1[0].IntValue;			\
+      for (i = 0; i < Nx*Ny; i++, out++, M2++) {	\
+	*out = OP;					\
+      }							\
+      break;						\
+    }							\
+  }
 
   switch (op[0]) { 
@@ -645,5 +724,5 @@
     case '-': SM_FUNC(M1 - *M2);
     case '*': SM_FUNC(M1 * *M2);
-    case '/': SM_FUNC(M1 / *M2);
+    case '/': SM_FUNC(M1 / (float) *M2);
     case '%': SM_FUNC((int) M1 % (int) *M2);
     case '^': SM_FUNC(pow (M1, *M2));
@@ -684,54 +763,62 @@
   char line[512]; // this is only used to report an error 
 
-# define SS_FUNC(OP)				\
-  if ((V1->type == 'S') && (V2->type == 'S')) { \
-    opihi_flt M1 = V1[0].FltValue;		\
-    opihi_flt M2 = V2[0].FltValue;		\
-    OUT[0].type = 'S';				\
-    OUT[0].FltValue = OP;			\
-    break;					\
-  }						\
-  if ((V1->type == 'S') && (V2->type == 's')) { \
-    opihi_flt M1 = V1[0].FltValue;		\
-    opihi_int M2 = V2[0].IntValue;		\
-    OUT[0].type = 'S';				\
-    OUT[0].FltValue = OP;			\
-    break;					\
-  }						\
-  if ((V1->type == 's') && (V2->type == 'S')) { \
-    opihi_int M1 = V1[0].IntValue;		\
-    opihi_flt M2 = V2[0].FltValue;		\
-    OUT[0].type = 'S';				\
-    OUT[0].FltValue = OP;			\
-    break;					\
-  }						\
-  if ((V1->type == 's') && (V2->type == 's')) { \
-    opihi_int M1 = V1[0].IntValue;		\
-    opihi_int M2 = V2[0].IntValue;		\
-    OUT[0].type = 's';				\
-    OUT[0].IntValue = OP;			\
-    break;					\
+# define SS_FUNC(FTYPE,OP) {						\
+    if ((V1->type == 'S') && (V2->type == 'S')) {			\
+      opihi_flt M1 = V1[0].FltValue;					\
+      opihi_flt M2 = V2[0].FltValue;					\
+      OUT[0].type = 'S';						\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((V1->type == 'S') && (V2->type == 's')) {			\
+      opihi_flt M1 = V1[0].FltValue;					\
+      opihi_int M2 = V2[0].IntValue;					\
+      OUT[0].type = 'S';						\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((V1->type == 's') && (V2->type == 'S')) {			\
+      opihi_int M1 = V1[0].IntValue;					\
+      opihi_flt M2 = V2[0].FltValue;					\
+      OUT[0].type = 'S';						\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((FTYPE == 'S') && (V1->type == 's') && (V2->type == 's')) {	\
+      opihi_int M1 = V1[0].IntValue;					\
+      opihi_int M2 = V2[0].IntValue;					\
+      OUT[0].type = 'S';						\
+      OUT[0].FltValue = OP;						\
+      break;								\
+    }									\
+    if ((V1->type == 's') && (V2->type == 's')) {			\
+      opihi_int M1 = V1[0].IntValue;					\
+      opihi_int M2 = V2[0].IntValue;					\
+      OUT[0].type = 's';						\
+      OUT[0].IntValue = OP;						\
+      break;								\
+    }									\
   }
 
   switch (op[0]) { 
-    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 '@': SS_FUNC(DEG_RAD*atan2 (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);
+    case '+': SS_FUNC('s', M1 + M2);
+    case '-': SS_FUNC('s', M1 - M2);
+    case '*': SS_FUNC('s', M1 * M2);
+    case '/': SS_FUNC('S', M1 / (opihi_flt) M2);
+    case '%': SS_FUNC('s', (int) M1 % (int) M2);
+    case '^': SS_FUNC('S', pow (M1, M2));
+    case '@': SS_FUNC('S', DEG_RAD*atan2 (M1, M2));
+    case 'D': SS_FUNC('s', MIN (M1, M2));
+    case 'U': SS_FUNC('s', MAX (M1, M2));
+    case '<': SS_FUNC('s', (M1 < M2) ? 1 : 0);
+    case '>': SS_FUNC('s', (M1 > M2) ? 1 : 0);
+    case '&': SS_FUNC('s', ((int)M1 & (int)M2));
+    case '|': SS_FUNC('s', ((int)M1 | (int)M2));
+    case 'E': SS_FUNC('s', (M1 == M2) ? 1 : 0);
+    case 'N': SS_FUNC('s', (M1 != M2) ? 1 : 0);
+    case 'L': SS_FUNC('s', (M1 <= M2) ? 1 : 0);
+    case 'G': SS_FUNC('s', (M1 >= M2) ? 1 : 0);
+    case 'A': SS_FUNC('s', (M1 && M2) ? 1 : 0);
+    case 'O': SS_FUNC('s', (M1 || M2) ? 1 : 0);
     default:
       sprintf (line, "error: op %c not defined!", op[0]);
@@ -878,34 +965,34 @@
 
 # define V_FUNC(OP,FTYPE) {					\
-  if (V1->vector->type == OPIHI_FLT) {				\
-    CopyVector (OUT[0].vector, V1[0].vector);			\
-    opihi_flt *M1  = V1[0].vector[0].elements.Flt;		\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M1++) {			\
-      *out = OP;						\
+    if (V1->vector->type == OPIHI_FLT) {			\
+      CopyVector (OUT[0].vector, V1[0].vector);			\
+      opihi_flt *M1  = V1[0].vector[0].elements.Flt;		\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
+      for (i = 0; i < Nx; i++, out++, M1++) {			\
+	*out = OP;						\
+      }								\
+      clear_stack (V1);						\
+      return (TRUE);						\
     }								\
-    clear_stack (V1);						\
-    return (TRUE);						\
-  }								\
-  if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {	\
-    MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);	\
-    opihi_int *M1  = V1[0].vector[0].elements.Int;		\
-    opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
-    for (i = 0; i < Nx; i++, out++, M1++) {			\
-      *out = OP;						\
+    if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {	\
+      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);	\
+      opihi_int *M1  = V1[0].vector[0].elements.Int;		\
+      opihi_flt *out = OUT[0].vector[0].elements.Flt;		\
+      for (i = 0; i < Nx; i++, out++, M1++) {			\
+	*out = OP;						\
+      }								\
+      clear_stack (V1);						\
+      return (TRUE);						\
     }								\
-    clear_stack (V1);						\
-    return (TRUE);						\
-  }								\
-  if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {	\
-    CopyVector (OUT[0].vector, V1[0].vector);			\
-    opihi_int *M1  = V1[0].vector[0].elements.Int;		\
-    opihi_int *out = OUT[0].vector[0].elements.Int;		\
-    for (i = 0; i < Nx; i++, out++, M1++) {			\
-      *out = OP;						\
-    }								\
-    clear_stack (V1);						\
-    return (TRUE);						\
-  } }							
+    if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {	\
+      CopyVector (OUT[0].vector, V1[0].vector);			\
+      opihi_int *M1  = V1[0].vector[0].elements.Int;		\
+      opihi_int *out = OUT[0].vector[0].elements.Int;		\
+      for (i = 0; i < Nx; i++, out++, M1++) {			\
+	*out = OP;						\
+      }								\
+      clear_stack (V1);						\
+      return (TRUE);						\
+    } }							
 
   if (!strcmp (op, "="))      V_FUNC(*M1, 's');
