From 3fbd60c2335bc4ad621768e5f93c08e0ca61a1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 31 Aug 2010 08:54:51 +0000 Subject: [PATCH] [CONFIGURATION] * NEW: Check for missing mathematical function directly instead of relying on operating system detection. git-svn-id: svn://localhost/gambas/trunk@3166 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- acinclude.m4 | 18 +++++++++++++++++- main/configure.ac | 1 + main/gbx/gbx_math.c | 19 ++++++++++++------- main/gbx/gbx_math.h | 24 ++++++++++++++++++------ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index c45f80bae..576766787 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -194,7 +194,7 @@ AC_DEFUN([GB_INIT], dnl AC_FUNC_WAIT3 dnl AC_CHECK_FUNCS(getcwd gettimeofday mkdir rmdir select socket strdup strerror strtod strtol sysinfo) - AC_REPLACE_FUNCS(setenv unsetenv getdomainname getpt cfmakeraw) + AC_CHECK_FUNCS(setenv unsetenv getdomainname getpt cfmakeraw) dnl ---- Checks for libraries @@ -342,6 +342,7 @@ AC_DEFUN([GB_INIT], rm -f DISABLED ]) + ## --------------------------------------------------------------------------- ## GB_THREAD ## Detect threading compiler options @@ -405,6 +406,21 @@ AC_DEFUN([GB_MATH], ]) +## --------------------------------------------------------------------------- +## GB_MATH_FUNC +## Detect which mathematical functions are available +## --------------------------------------------------------------------------- + +AC_DEFUN([GB_MATH_FUNC], +[ + dnl AC_CHECK_LIB(m, main, true) + ac_save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -lm" + AC_CHECK_FUNCS(log10l fabsl powl modfl exp10 exp2 log2) + LDFLAGS=$ac_save_LDFLAGS +]) + + ## --------------------------------------------------------------------------- ## GB_SYSTEM ## Detects the target system and its architecture diff --git a/main/configure.ac b/main/configure.ac index 2370b110a..eb966a9a3 100644 --- a/main/configure.ac +++ b/main/configure.ac @@ -4,6 +4,7 @@ AC_INIT AC_CONFIG_SRCDIR([configure.ac]) AC_CONFIG_MACRO_DIR([m4]) GB_INIT(main) +GB_MATH_FUNC LT_INIT AM_PROG_CC_C_O diff --git a/main/gbx/gbx_math.c b/main/gbx/gbx_math.c index ece77a767..c8e6b78cb 100644 --- a/main/gbx/gbx_math.c +++ b/main/gbx/gbx_math.c @@ -177,50 +177,55 @@ double rnd(void) return (double)val / 18446744073709551616.0; //0xFFFFFFFFFFFFFFFFULL; } - -#if defined(OS_FREEBSD) || defined(OS_OPENBSD) - +#ifndef HAVE_EXP10 double exp10(double x) { return pow(10, x); } +#endif +#ifndef HAVE_LOG2 double log2(double x) { return log(x) / M_LN2; } +#endif +#ifndef HAVE_EXP2 double exp2(double x) { return pow(2, x); } - #endif -#if defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(ARCH_ARM) || defined(OS_CYGWIN) - +#ifndef HAVE_LOG10L long double log10l(long double x) { return log10((double) x); } +#endif +#ifndef HAVE_FABSL long double fabsl(long double x) { return fabs((double) x); } +#endif +#ifndef HAVE_POWL long double powl(long double x, long double y) { return pow((double) x, (double) y); } +#endif +#ifndef HAVE_MODFL long double modfl(long double x, long double *iptr) { double val; return modf((double)x, &val); *iptr = val; } - #endif void MATH_init(void) diff --git a/main/gbx/gbx_math.h b/main/gbx/gbx_math.h index b60d1c897..9e773e42c 100644 --- a/main/gbx/gbx_math.h +++ b/main/gbx/gbx_math.h @@ -42,20 +42,32 @@ double rnd(void); #define deg(_x) ((_x) * 180 / M_PI) #define rad(_x) ((_x) * M_PI / 180) -#if defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_CYGWIN) +#ifndef HAVE_EXP10 double exp10(double x); -#ifdef log2 -#undef log2 #endif + +#ifndef HAVE_LOG2 double log2(double x); +#endif + +#ifndef HAVE_EXP2 double exp2(double x); #endif -#if defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_CYGWIN) || defined(ARCH_ARM) +#ifndef HAVE_LOG10L long double log10l(long double x); +#endif + +#ifndef HAVE_FABSL long double fabsl(long double x); -long double powl(long double x, long double y); -long double modfl(long double x, long double *p); +#endif + +#ifndef HAVE_POWL +long double powl(long double x); +#endif + +#ifndef HAVE_MODFL +long double modfl(long double x); #endif #endif