[asterisk-commits] dhubbard: trunk r65906 - in /trunk: ./ funcs/func_math.c

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


Author: dhubbard
Date: Thu May 24 10:35:50 2007
New Revision: 65906

URL: http://svn.digium.com/view/asterisk?view=rev&rev=65906
Log:
Merged revisions 65866 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r65866 | dhubbard | 2007-05-24 10:08:56 -0500 (Thu, 24 May 2007) | 1 line

merged qwell's func_math patch for issue 9507
........

Modified:
    trunk/   (props changed)
    trunk/funcs/func_math.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/funcs/func_math.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_math.c?view=diff&rev=65906&r1=65905&r2=65906
==============================================================================
--- trunk/funcs/func_math.c (original)
+++ trunk/funcs/func_math.c Thu May 24 10:35:50 2007
@@ -77,6 +77,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);
@@ -96,13 +97,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, '/'))) {
@@ -141,6 +141,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)
@@ -184,6 +190,9 @@
 		return -1;
 	}
 
+	if (negvalue1)
+		fnum1 = 0 - fnum1;
+
 	switch (iaction) {
 	case ADDFUNCTION:
 		ftmp = fnum1 + fnum2;



More information about the asterisk-commits mailing list