[svn-commits] tilghman: trunk r49076 - /trunk/funcs/func_math.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sat Dec 30 22:20:18 MST 2006


Author: tilghman
Date: Sat Dec 30 23:20:18 2006
New Revision: 49076

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49076
Log:
Add power and right/left shift functions (Issue 7959)

Modified:
    trunk/funcs/func_math.c

Modified: trunk/funcs/func_math.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_math.c?view=diff&rev=49076&r1=49075&r2=49076
==============================================================================
--- trunk/funcs/func_math.c (original)
+++ trunk/funcs/func_math.c Sat Dec 30 23:20:18 2006
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <math.h>
 #include <sys/types.h>
 
 #include "asterisk/module.h"
@@ -47,6 +48,9 @@
 	MULTIPLYFUNCTION,
 	SUBTRACTFUNCTION,
 	MODULUSFUNCTION,
+	POWFUNCTION,
+	SHLEFTFUNCTION,
+	SHRIGHTFUNCTION,
 	GTFUNCTION,
 	LTFUNCTION,
 	GTEFUNCTION,
@@ -105,12 +109,18 @@
 	} 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 @@
 		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 @@
 
 			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;



More information about the svn-commits mailing list