From 48f56ba8b4fadde2cb2f208414095577bba36851 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Sat, 22 Sep 2007 02:07:53 +0000 Subject: Fixes for FreeBSD... testing for every conceivable math function now git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@83517 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/ast_expr2.y | 333 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 240 insertions(+), 93 deletions(-) (limited to 'main/ast_expr2.y') diff --git a/main/ast_expr2.y b/main/ast_expr2.y index 3b698c477..45786246d 100644 --- a/main/ast_expr2.y +++ b/main/ast_expr2.y @@ -14,40 +14,186 @@ #include #include +#include "asterisk.h" -/* Instead of looking for an arbitrary keyword, just test for various C99 function presence */ -#if (defined(HAVE_ROUNDL) || defined(HAVE_TRUNCL) || defined(HAVE_LOG10L) || defined(HAVE_LOG2L)) -#ifndef __USE_ISOC99 -#define __USE_ISOC99 +#define FP___PRINTF "%.18Lg" +#define FP___TYPE long double + +#ifdef HAVE_COSL +#define FUNC_COS cosl +#else +#ifdef HAVE_COS +#define FUNC_COS (long double)cos +#else +#undef FUNC_COS #endif #endif -#ifdef __USE_ISOC99 -#define FP___PRINTF "%.18Lg" -#define FP___FMOD fmodl -#define FP___STRTOD strtold -#define FP___TYPE long double -#define FUNC_COS cosl -#define FUNC_SIN sinl -#define FUNC_TAN tanl -#define FUNC_ACOS acosl -#define FUNC_ASIN asinl -#define FUNC_ATAN atanl -#define FUNC_ATAN2 atan2l -#define FUNC_POW powl -#define FUNC_SQRT sqrtl +#ifdef HAVE_SINL +#define FUNC_SIN sinl +#else +#ifdef HAVE_SIN +#define FUNC_SIN (long double)sin +#else +#undef FUNC_SIN +#endif +#endif + +#ifdef HAVE_TANL +#define FUNC_TAN tanl +#else +#ifdef HAVE_TAN +#define FUNC_TAN (long double)tan +#else +#undef FUNC_TAN +#endif +#endif + +#ifdef HAVE_ACOSL +#define FUNC_ACOS acosl +#else +#ifdef HAVE_ACOS +#define FUNC_ACOS (long double)acos +#else +#undef FUNC_ACOS +#endif +#endif + +#ifdef HAVE_ASINL +#define FUNC_ASIN asinl +#else +#ifdef HAVE_ASIN +#define FUNC_ASIN (long double)asin +#else +#undef FUNC_ASIN +#endif +#endif + +#ifdef HAVE_ATANL +#define FUNC_ATAN atanl +#else +#ifdef HAVE_ATAN +#define FUNC_ATAN (long double)atan +#else +#undef FUNC_ATAN +#endif +#endif + +#ifdef HAVE_ATAN2L +#define FUNC_ATAN2 atan2l +#else +#ifdef HAVE_ATAN2 +#define FUNC_ATAN2 (long double)atan2 +#else +#undef FUNC_ATAN2 +#endif +#endif + +#ifdef HAVE_POWL +#define FUNC_POW powl +#else +#ifdef HAVE_POW +#define FUNC_POW (long double)pow +#else +#undef FUNC_POW +#endif +#endif + +#ifdef HAVE_SQRTL +#define FUNC_SQRT sqrtl +#else +#ifdef HAVE_SQRT +#define FUNC_SQRT (long double)sqrt +#else +#undef FUNC_SQRT +#endif +#endif + +#ifdef HAVE_RINTL +#define FUNC_RINT rintl +#else +#ifdef HAVE_RINT +#define FUNC_RINT (long double)rint +#else +#undef FUNC_RINT +#endif +#endif + +#ifdef HAVE_EXPL +#define FUNC_EXP expl +#else +#ifdef HAVE_EXP +#define FUNC_EXP (long double)exp +#else +#undef FUNC_EXP +#endif +#endif + +#ifdef HAVE_LOGL +#define FUNC_LOG logl +#else +#ifdef HAVE_LOG +#define FUNC_LOG (long double)log +#else +#undef FUNC_LOG +#endif +#endif + +#ifdef HAVE_REMINDERL +#define FUNC_REMINDER reminderl +#else +#ifdef HAVE_REMINDER +#define FUNC_REMINDER (long double)reminder +#else +#undef FUNC_REMINDER +#endif +#endif + +#ifdef HAVE_FMODL +#define FUNC_FMOD fmodl +#else +#ifdef HAVE_FMOD +#define FUNC_FMOD (long double)fmod +#else +#undef FUNC_FMOD +#endif +#endif + +#ifdef HAVE_STRTOLD +#define FUNC_STRTOD strtold +#else +#ifdef HAVE_STRTOD +#define FUNC_STRTOD (long double)strtod +#else +#undef FUNC_STRTOD +#endif +#endif + +#ifdef HAVE_FLOORL #define FUNC_FLOOR floorl +#else +#ifdef HAVE_FLOOR +#define FUNC_FLOOR (long double)floor +#else +#undef FUNC_FLOOR +#endif /* defined(HAVE_FLOOR) */ +#endif /* defined(HAVE_FLOORL) */ + +#ifdef HAVE_CEILL #define FUNC_CEIL ceill -#define FUNC_RINT rintl -#define FUNC_EXP expl -#define FUNC_LOG logl -#define FUNC_REMAINDER remainderl +#else +#ifdef HAVE_CEIL +#define FUNC_CEIL (long double)ceil +#else +#undef FUNC_CEIL +#endif /* defined(HAVE_CEIL) */ +#endif /* defined(HAVE_CEILL) */ #ifdef HAVE_ROUNDL #define FUNC_ROUND roundl #else /* HAVE_ROUNDL */ #ifdef HAVE_ROUND -#define FUNC_ROUND round +#define FUNC_ROUND (long double)round #else /* HAVE_ROUND */ #undef FUNC_ROUND #endif /* HAVE_ROUND */ @@ -57,7 +203,7 @@ #define FUNC_TRUNC truncl #else /* HAVE_TRUNCL */ #ifdef HAVE_TRUNC -#define FUNC_TRUNC trunc +#define FUNC_TRUNC (long double)trunc #else /* HAVE_TRUNC */ #undef FUNC_TRUNC #endif /* HAVE_TRUNC */ @@ -70,86 +216,50 @@ #ifdef HAVE_EXP2L #define FUNC_EXP2 exp2l #else +#if (defined(HAVE_EXPL) && defined(HAVE_LOGL)) #define FUNC_EXP2(x) expl((x) * logl(2.0)) -#endif +#else +#if (defined(HAVE_EXP) && defined(HAVE_LOG)) +#define FUNC_EXP2(x) (long double)exp((x) * log(2.0)) +#endif /* defined(HAVE_EXP) && defined(HAVE_LOG) */ +#endif /* defined(HAVE_EXPL) && defined(HAVE_LOGL) */ +#endif /* defined(HAVE_EXP2L) */ #ifdef HAVE_EXP10L #define FUNC_EXP10 exp10l #else +#if (defined(HAVE_EXPL) && defined(HAVE_LOGL)) #define FUNC_EXP10(x) expl((x) * logl(10.0)) -#endif +#else +#if (defined(HAVE_EXP) && defined(HAVE_LOG)) +#define FUNC_EXP10(x) (long double)exp((x) * log(10.0)) +#endif /* defined(HAVE_EXP) && defined(HAVE_LOG) */ +#endif /* defined(HAVE_EXPL) && defined(HAVE_LOGL) */ +#endif /* defined(HAVE_EXP10L) */ #ifdef HAVE_LOG2L #define FUNC_LOG2 log2l #else +#ifdef HAVE_LOGL #define FUNC_LOG2(x) (logl(x) / logl(2.0)) -#endif +#else +#ifdef HAVE_LOG +#define FUNC_LOG2(x) ((long double)log(x) / log(2.0)) +#endif /* defined(HAVE_LOG) */ +#endif /* defined(HAVE_LOGL) */ +#endif /* defined(HAVE_LOG2L) */ #ifdef HAVE_LOG10L #define FUNC_LOG10 log10l #else +#ifdef HAVE_LOGL #define FUNC_LOG10(x) (logl(x) / logl(10.0)) -#endif - -#else /* defined(__USE_ISOC99) */ - -#define FP___PRINTF "%.16g" -#define FP___FMOD fmod -#define FP___STRTOD strtod -#define FP___TYPE double -#define FUNC_COS cos -#define FUNC_SIN sin -#define FUNC_TAN tan -#define FUNC_ACOS acos -#define FUNC_ASIN asin -#define FUNC_ATAN atan -#define FUNC_ATAN2 atan2 -#define FUNC_POW pow -#define FUNC_SQRT sqrt -#define FUNC_FLOOR floor -#define FUNC_CEIL ceil -#define FUNC_RINT rint -#define FUNC_EXP exp -#define FUNC_LOG log -#define FUNC_REMAINDER remainder - -#ifdef HAVE_ROUND -#define FUNC_ROUND round #else -#undef FUNC_ROUND -#endif - -#ifdef HAVE_TRUNC -#define FUNC_TRUNC round -#else -#undef FUNC_TRUNC -#endif - -#ifdef HAVE_EXP2 -#define FUNC_EXP2 exp2 -#else -#define FUNC_EXP2(x) exp((x) * log(2.0)) -#endif - -#ifdef HAVE_EXP10 -#define FUNC_EXP10 exp10 -#else -#define FUNC_EXP10(x) exp((x) * log(10.0)) -#endif - -#ifdef HAVE_LOG2 -#define FUNC_LOG2 log2 -#else -#define FUNC_LOG2(x) (log(x) / log(2.0)) -#endif - -#ifdef HAVE_LOG10 -#define FUNC_LOG10 log10 -#else -#define FUNC_LOG10(x) (log(x) / log(10.0)) -#endif - -#endif /* defined(__USE_ISOC99) */ +#ifdef HAVE_LOG +#define FUNC_LOG10(x) ((long double)log(x) / log(10.0)) +#endif /* defined(HAVE_LOG) */ +#endif /* defined(HAVE_LOGL) */ +#endif /* defined(HAVE_LOG10L) */ #include @@ -170,7 +280,6 @@ #include #include -#include "asterisk.h" #include "asterisk/ast_expr.h" #include "asterisk/logger.h" #ifndef STANDALONE @@ -534,7 +643,7 @@ to_number (struct val *vp) /* vp->type == AST_EXPR_numeric_string, make it numeric */ errno = 0; - i = FP___STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */ + i = FUNC_STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */ if (errno != 0) { ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s); free(vp->u.s); @@ -744,8 +853,9 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s)) { struct val *result; - - if (strcmp(funcname->u.s,"COS") == 0) { + if (0) { +#ifdef FUNC_COS + } else if (strcmp(funcname->u.s,"COS") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); result = make_number(FUNC_COS(arglist->val->u.i)); @@ -754,6 +864,8 @@ 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 +#ifdef FUNC_SIN } else if (strcmp(funcname->u.s,"SIN") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -763,6 +875,8 @@ 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 +#ifdef FUNC_TAN } else if (strcmp(funcname->u.s,"TAN") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -772,6 +886,8 @@ 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 +#ifdef FUNC_ACOS } else if (strcmp(funcname->u.s,"ACOS") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -781,6 +897,8 @@ 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 +#ifdef FUNC_ASIN } else if (strcmp(funcname->u.s,"ASIN") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -790,6 +908,8 @@ 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 +#ifdef FUNC_ATAN } else if (strcmp(funcname->u.s,"ATAN") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -799,6 +919,8 @@ 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 +#ifdef FUNC_ATAN2 } else if (strcmp(funcname->u.s,"ATAN2") == 0) { if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){ to_number(arglist->val); @@ -809,6 +931,8 @@ 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 +#ifdef FUNC_POW } else if (strcmp(funcname->u.s,"POW") == 0) { if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){ to_number(arglist->val); @@ -819,6 +943,8 @@ 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 +#ifdef FUNC_SQRT } else if (strcmp(funcname->u.s,"SQRT") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -828,6 +954,8 @@ 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 +#ifdef FUNC_FLOOR } else if (strcmp(funcname->u.s,"FLOOR") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -837,6 +965,8 @@ 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 +#ifdef FUNC_CEIL } else if (strcmp(funcname->u.s,"CEIL") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -846,6 +976,7 @@ 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 #ifdef FUNC_ROUND } else if (strcmp(funcname->u.s,"ROUND") == 0) { if (arglist && !arglist->right && arglist->val){ @@ -857,6 +988,7 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru return make_number(0.0); } #endif /* defined(FUNC_ROUND) */ +#ifdef FUNC_RINT } else if (strcmp(funcname->u.s,"RINT") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -866,6 +998,7 @@ 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 #ifdef FUNC_TRUNC } else if (strcmp(funcname->u.s,"TRUNC") == 0) { if (arglist && !arglist->right && arglist->val){ @@ -877,6 +1010,7 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru return make_number(0.0); } #endif /* defined(FUNC_TRUNC) */ +#ifdef FUNC_EXP } else if (strcmp(funcname->u.s,"EXP") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -886,6 +1020,8 @@ 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 +#ifdef FUNC_EXP2 } else if (strcmp(funcname->u.s,"EXP2") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -895,6 +1031,8 @@ 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 +#ifdef FUNC_EXP10 } else if (strcmp(funcname->u.s,"EXP10") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -904,6 +1042,8 @@ 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 +#ifdef FUNC_LOG } else if (strcmp(funcname->u.s,"LOG") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -913,6 +1053,8 @@ 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 +#ifdef FUNC_LOG2 } else if (strcmp(funcname->u.s,"LOG2") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -922,6 +1064,8 @@ 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 +#ifdef FUNC_LOG10 } else if (strcmp(funcname->u.s,"LOG10") == 0) { if (arglist && !arglist->right && arglist->val){ to_number(arglist->val); @@ -931,6 +1075,8 @@ 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 +#ifdef FUNC_REMAINDER } else if (strcmp(funcname->u.s,"REMAINDER") == 0) { if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){ to_number(arglist->val); @@ -941,6 +1087,7 @@ 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 { /* is this a custom function we should execute and collect the results of? */ #ifndef STANDALONE @@ -957,7 +1104,7 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru f->read(chan, funcname->u.s, argbuf, workspace, sizeof(workspace)); free(argbuf); if (is_really_num(workspace)) - return make_number(FP___STRTOD(workspace,(char **)NULL)); + return make_number(FUNC_STRTOD(workspace,(char **)NULL)); else return make_str(workspace); } else { @@ -1435,7 +1582,7 @@ op_rem (struct val *a, struct val *b) return(b); } - r = make_number (FP___FMOD(a->u.i, b->u.i)); /* either fmod or fmodl if FP___TYPE is available */ + r = make_number (FUNC_FMOD(a->u.i, b->u.i)); /* either fmod or fmodl if FP___TYPE is available */ /* chk_rem necessary ??? */ free_value (a); free_value (b); -- cgit v1.2.3