]> granicus.if.org Git - python/commitdiff
Issue #11888: Use system log2() when available
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 9 May 2011 10:45:41 +0000 (12:45 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 9 May 2011 10:45:41 +0000 (12:45 +0200)
I expect the system libc to use more accurate functions than Python. The GNU
libc uses for example FYL2X and FYL2XP1 hardware instructions on Intel FPU.

Modules/mathmodule.c
configure
configure.in
pyconfig.h.in

index 14d008af13cc6e21c7df395db35c035deb819989..cebb4ff91ba58e6dc25b5196e28643809fe3c389 100644 (file)
@@ -602,6 +602,9 @@ m_log2(double x)
     }
 
     if (x > 0.0) {
+#ifdef HAVE_LOG2
+        return log2(x);
+#else
         double m;
         int e;
         m = frexp(x, &e);
@@ -617,6 +620,7 @@ m_log2(double x)
         else {
             return log(m) / log(2.0) + e;
         }
+#endif
     }
     else if (x == 0.0) {
         errno = EDOM;
index da4c9024bfa1a34a7cfff1045d041969d4cc5fb8..6d3f85efbdbf97484a233162ba9f45e7dd29f52b 100755 (executable)
--- a/configure
+++ b/configure
@@ -11864,7 +11864,7 @@ _ACEOF
 fi
 done
 
-for ac_func in hypot lgamma log1p round tgamma
+for ac_func in hypot lgamma log1p log2 round tgamma
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
index 49864f451f0586e8cc6ca7188a4c646423574c14..c6a94370990ebfe313f09c1adbe5ef800f0e4961 100644 (file)
@@ -2512,7 +2512,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
  futimens futimes \
  gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
  getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
- initgroups kill killpg lchmod lchown lockf linkat lstat lutimes mbrtowc mkdirat mkfifo \
+ initgroups kill killpg lchmod lchown lockf log2 linkat lstat lutimes mbrtowc mkdirat mkfifo \
  mkfifoat mknod mknodat mktime mremap nice openat pathconf pause plock poll \
  posix_fallocate posix_fadvise pread \
  pthread_init pthread_kill putenv pwrite readlink readlinkat readv realpath renameat \
@@ -3368,7 +3368,7 @@ LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
 AC_CHECK_FUNCS([acosh asinh atanh copysign erf erfc expm1 finite gamma])
-AC_CHECK_FUNCS([hypot lgamma log1p round tgamma])
+AC_CHECK_FUNCS([hypot lgamma log1p log2 round tgamma])
 AC_CHECK_DECLS([isinf, isnan, isfinite], [], [], [[#include <math.h>]])
 
 # On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
index 89b0c33e8a6446e43d7b671964a2e5c7294f7edb..55272f11ea5c3c1aa71bcb2f408b6f001662f6ec 100644 (file)
 /* Define to 1 if you have the `log1p' function. */
 #undef HAVE_LOG1P
 
+/* Define to 1 if you have the `log2' function. */
+#undef HAVE_LOG2
+
 /* Define this if you have the type long double. */
 #undef HAVE_LONG_DOUBLE