[Python-checkins] cpython: Issue #11888: Use system log2() when available

victor.stinner python-checkins at python.org
Mon May 9 12:46:32 CEST 2011


http://hg.python.org/cpython/rev/565f43f6bed4
changeset:   69975:565f43f6bed4
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon May 09 12:45:41 2011 +0200
summary:
  Issue #11888: Use system log2() when available

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.

files:
  Modules/mathmodule.c |  4 ++++
  configure            |  2 +-
  configure.in         |  4 ++--
  pyconfig.h.in        |  3 +++
  4 files changed, 10 insertions(+), 3 deletions(-)


diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -602,6 +602,9 @@
     }
 
     if (x > 0.0) {
+#ifdef HAVE_LOG2
+        return log2(x);
+#else
         double m;
         int e;
         m = frexp(x, &e);
@@ -617,6 +620,7 @@
         else {
             return log(m) / log(2.0) + e;
         }
+#endif
     }
     else if (x == 0.0) {
         errno = EDOM;
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -11864,7 +11864,7 @@
 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"
diff --git a/configure.in b/configure.in
--- a/configure.in
+++ b/configure.in
@@ -2512,7 +2512,7 @@
  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="$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
diff --git a/pyconfig.h.in b/pyconfig.h.in
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -476,6 +476,9 @@
 /* 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
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list