aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_math.c
diff options
context:
space:
mode:
authordhubbard <dhubbard@f38db490-d61c-443f-a65b-d21fe96a405b>2007-05-24 15:35:50 +0000
committerdhubbard <dhubbard@f38db490-d61c-443f-a65b-d21fe96a405b>2007-05-24 15:35:50 +0000
commit84e099c6765095745bb02aeb30c310bd16b90d66 (patch)
tree7d274f46c83c111b673d39342137a8b9f61a0888 /funcs/func_math.c
parentd01a4492982a48a29e9b7dcc04356f0a589d67f7 (diff)
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 ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@65906 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_math.c')
-rw-r--r--funcs/func_math.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/funcs/func_math.c b/funcs/func_math.c
index 703c9e9b1..bdcbb69ff 100644
--- a/funcs/func_math.c
+++ b/funcs/func_math.c
@@ -77,6 +77,7 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse,
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 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse,
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 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse,
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 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse,
return -1;
}
+ if (negvalue1)
+ fnum1 = 0 - fnum1;
+
switch (iaction) {
case ADDFUNCTION:
ftmp = fnum1 + fnum2;