aboutsummaryrefslogtreecommitdiffstats
path: root/main/ast_expr2.y
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-08 21:01:28 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-08 21:01:28 +0000
commit6917c984363c8967aa5d32812e2b89303ae40197 (patch)
treee26097b2e32f70833c0f6cdbc88889414c2b31f0 /main/ast_expr2.y
parentd5b88e332d74145e3d53290eb61f1c66410bd3aa (diff)
Restore EXP2 and LOG2 functions, by providing mathematical identify functions, when the underlying C functions are not available.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@73911 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/ast_expr2.y')
-rw-r--r--main/ast_expr2.y43
1 files changed, 37 insertions, 6 deletions
diff --git a/main/ast_expr2.y b/main/ast_expr2.y
index 126a02856..5ba348867 100644
--- a/main/ast_expr2.y
+++ b/main/ast_expr2.y
@@ -41,14 +41,27 @@
#define FUNC_RINT rintl
#define FUNC_TRUNC truncl
#define FUNC_EXP expl
-#ifdef HAVE_EXP2
+#ifdef HAVE_EXP2L
#define FUNC_EXP2 exp2l
+#else
+#define FUNC_EXP2(x) expl((x) * logl(2))
+#endif
+#ifdef HAVE_EXP10L
+#define FUNC_EXP10 exp10l
+#else
+#define FUNC_EXP10(x) expl((x) * logl(10))
#endif
#define FUNC_LOG logl
-#ifdef HAVE_LOG2
+#ifdef HAVE_LOG2L
#define FUNC_LOG2 log2l
+#else
+#define FUNC_LOG2(x) (logl(x) / logl(2))
#endif
+#ifdef HAVE_LOG10L
#define FUNC_LOG10 log10l
+#else
+#define FUNC_LOG10(x) (logl(x) / logl(10))
+#endif
#define FUNC_REMAINDER remainderl
#else
#define FP___PRINTF "%.16g"
@@ -72,12 +85,25 @@
#define FUNC_EXP exp
#ifdef HAVE_EXP2
#define FUNC_EXP2 exp2
+#else
+#define FUNC_EXP2(x) exp((x) * log(2))
+#endif
+#ifdef HAVE_EXP10
+#define FUNC_EXP10 exp10
+#else
+#define FUNC_EXP10(x) exp((x) * log(10))
#endif
#define FUNC_LOG log
#ifdef HAVE_LOG2
#define FUNC_LOG2 log2
+#else
+#define FUNC_LOG2(x) (log(x) / log(2))
#endif
+#ifdef HAVE_LOG10
#define FUNC_LOG10 log10
+#else
+#define FUNC_LOG10(x) (log(x) / log(10))
+#endif
#define FUNC_REMAINDER remainder
#endif
@@ -811,7 +837,6 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
-#ifdef HAVE_EXP2
} else if (strcmp(funcname->u.s,"EXP2") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
@@ -821,7 +846,15 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
-#endif
+ } else if (strcmp(funcname->u.s,"EXP10") == 0) {
+ if (arglist && !arglist->right && arglist->val){
+ to_number(arglist->val);
+ result = make_number(FUNC_EXP10(arglist->val->u.i));
+ return result;
+ } else {
+ ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
+ return make_number(0.0);
+ }
} else if (strcmp(funcname->u.s,"LOG") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
@@ -831,7 +864,6 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
-#ifdef HAVE_LOG2
} else if (strcmp(funcname->u.s,"LOG2") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
@@ -841,7 +873,6 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
-#endif
} else if (strcmp(funcname->u.s,"LOG10") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);