aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_math.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-31 05:20:18 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-31 05:20:18 +0000
commit7f7f1f60964a14d8a7941c05645ea2463f88ebe1 (patch)
tree4f05dbe287ae960cf380d30f9ac3fee2be0cb8b7 /funcs/func_math.c
parent3ad2a81a5dbc3ecf16066f488111b172bbf4ab1a (diff)
Add power and right/left shift functions (Issue 7959)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@49076 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_math.c')
-rw-r--r--funcs/func_math.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/funcs/func_math.c b/funcs/func_math.c
index 386897dbd..b5ad4358f 100644
--- a/funcs/func_math.c
+++ b/funcs/func_math.c
@@ -31,6 +31,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <math.h>
#include <sys/types.h>
#include "asterisk/module.h"
@@ -47,6 +48,9 @@ enum TypeOfFunctions {
MULTIPLYFUNCTION,
SUBTRACTFUNCTION,
MODULUSFUNCTION,
+ POWFUNCTION,
+ SHLEFTFUNCTION,
+ SHRIGHTFUNCTION,
GTFUNCTION,
LTFUNCTION,
GTEFUNCTION,
@@ -105,12 +109,18 @@ static int math(struct ast_channel *chan, char *cmd, char *parse,
} else if ((op = strchr(mvalue1, '%'))) {
iaction = MODULUSFUNCTION;
*op = '\0';
+ } else if ((op = strchr(mvalue1, '^'))) {
+ iaction = POWFUNCTION;
+ *op = '\0';
} else if ((op = strchr(mvalue1, '>'))) {
iaction = GTFUNCTION;
*op = '\0';
if (*(op + 1) == '=') {
*++op = '\0';
iaction = GTEFUNCTION;
+ } else if (*(op + 1) == '>') {
+ *++op = '\0';
+ iaction = SHRIGHTFUNCTION;
}
} else if ((op = strchr(mvalue1, '<'))) {
iaction = LTFUNCTION;
@@ -118,6 +128,9 @@ static int math(struct ast_channel *chan, char *cmd, char *parse,
if (*(op + 1) == '=') {
*++op = '\0';
iaction = LTEFUNCTION;
+ } else if (*(op + 1) == '<') {
+ *++op = '\0';
+ iaction = SHLEFTFUNCTION;
}
} else if ((op = strchr(mvalue1, '='))) {
*op = '\0';
@@ -194,6 +207,25 @@ static int math(struct ast_channel *chan, char *cmd, char *parse,
break;
}
+ case POWFUNCTION:
+ ftmp = pow(fnum1, fnum2);
+ break;
+ case SHLEFTFUNCTION:
+ {
+ int inum1 = fnum1;
+ int inum2 = fnum2;
+
+ ftmp = (inum1 << inum2);
+ break;
+ }
+ case SHRIGHTFUNCTION:
+ {
+ int inum1 = fnum1;
+ int inum2 = fnum2;
+
+ ftmp = (inum1 >> inum2);
+ break;
+ }
case GTFUNCTION:
ast_copy_string(buf, (fnum1 > fnum2) ? "TRUE" : "FALSE", len);
break;