Skip to content

Commit 8f9f8d6

Browse files
author
Victor Stinner
committed
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.
1 parent 936d518 commit 8f9f8d6

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

Modules/mathmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ m_log2(double x)
602602
}
603603

604604
if (x > 0.0) {
605+
#ifdef HAVE_LOG2
606+
return log2(x);
607+
#else
605608
double m;
606609
int e;
607610
m = frexp(x, &e);
@@ -617,6 +620,7 @@ m_log2(double x)
617620
else {
618621
return log(m) / log(2.0) + e;
619622
}
623+
#endif
620624
}
621625
else if (x == 0.0) {
622626
errno = EDOM;

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11864,7 +11864,7 @@ _ACEOF
1186411864
fi
1186511865
done
1186611866

11867-
for ac_func in hypot lgamma log1p round tgamma
11867+
for ac_func in hypot lgamma log1p log2 round tgamma
1186811868
do :
1186911869
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1187011870
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

configure.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
25122512
futimens futimes \
25132513
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
25142514
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
2515-
initgroups kill killpg lchmod lchown lockf linkat lstat lutimes mbrtowc mkdirat mkfifo \
2515+
initgroups kill killpg lchmod lchown lockf log2 linkat lstat lutimes mbrtowc mkdirat mkfifo \
25162516
mkfifoat mknod mknodat mktime mremap nice openat pathconf pause plock poll \
25172517
posix_fallocate posix_fadvise pread \
25182518
pthread_init pthread_kill putenv pwrite readlink readlinkat readv realpath renameat \
@@ -3368,7 +3368,7 @@ LIBS_SAVE=$LIBS
33683368
LIBS="$LIBS $LIBM"
33693369

33703370
AC_CHECK_FUNCS([acosh asinh atanh copysign erf erfc expm1 finite gamma])
3371-
AC_CHECK_FUNCS([hypot lgamma log1p round tgamma])
3371+
AC_CHECK_FUNCS([hypot lgamma log1p log2 round tgamma])
33723372
AC_CHECK_DECLS([isinf, isnan, isfinite], [], [], [[#include <math.h>]])
33733373

33743374
# On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@
476476
/* Define to 1 if you have the `log1p' function. */
477477
#undef HAVE_LOG1P
478478

479+
/* Define to 1 if you have the `log2' function. */
480+
#undef HAVE_LOG2
481+
479482
/* Define this if you have the type long double. */
480483
#undef HAVE_LONG_DOUBLE
481484

0 commit comments

Comments
 (0)