[asterisk-commits] dhubbard: branch 1.4 r65866 - /branches/1.4/funcs/func_math.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu May 24 08:08:56 MST 2007


Author: dhubbard
Date: Thu May 24 10:08:56 2007
New Revision: 65866

URL: http://svn.digium.com/view/asterisk?view=rev&rev=65866
Log:
merged qwell's func_math patch for issue 9507

Modified:
    branches/1.4/funcs/func_math.c

Modified: branches/1.4/funcs/func_math.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/funcs/func_math.c?view=diff&rev=65866&r1=65865&r2=65866
==============================================================================
--- branches/1.4/funcs/func_math.c (original)
+++ branches/1.4/funcs/func_math.c Thu May 24 10:08:56 2007
@@ -71,6 +71,7 @@
 	int iaction = -1;
 	int type_of_result = FLOAT_RESULT;
 	char *mvalue1, *mvalue2 = NULL, *mtype_of_result;
+	int negvalue1 = 0;
 	AST_DECLARE_APP_ARGS(args,
 			     AST_APP_ARG(argv0);
 			     AST_APP_ARG(argv1);
@@ -90,13 +91,12 @@
 
 	mvalue1 = args.argv0;
 
-	if ((op = strchr(mvalue1, '+'))) {
-		iaction = ADDFUNCTION;
-		*op = '\0';
-	} else if ((op = strchr(mvalue1, '-'))) {
-		iaction = SUBTRACTFUNCTION;
-		*op = '\0';
-	} else if ((op = strchr(mvalue1, '*'))) {
+	if (mvalue1[0] == '-') {
+		negvalue1 = 1;
+		mvalue1++;
+	}
+
+	if ((op = strchr(mvalue1, '*'))) {
 		iaction = MULTIPLYFUNCTION;
 		*op = '\0';
 	} else if ((op = strchr(mvalue1, '/'))) {
@@ -126,6 +126,12 @@
 			iaction = EQFUNCTION;
 		} else
 			op = NULL;
+	} else if ((op = strchr(mvalue1, '+'))) {
+		iaction = ADDFUNCTION;
+		*op = '\0';
+	} else if ((op = strchr(mvalue1, '-'))) { /* subtraction MUST always be last, in case we have a negative first number */
+		iaction = SUBTRACTFUNCTION;
+		*op = '\0';
 	}
 
 	if (op)
@@ -169,6 +175,9 @@
 		return -1;
 	}
 
+	if (negvalue1)
+		fnum1 = 0 - fnum1;
+
 	switch (iaction) {
 	case ADDFUNCTION:
 		ftmp = fnum1 + fnum2;



More information about the asterisk-commits mailing list