[Python-Dev] Mandrake vs glibc

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Sun, 15 Oct 2000 17:57:18 +0200


> So, if David's report is correct, and best I understand it you were
> all using 7.1 too with at least some level of optimization, it's A
> Mystery why CVS test_math.py succeeds on that system (its new
> math.sqrt(-1) test would probably fail; its new math.exp(+huge) test
> would almost certainly fail).  I'm anal enough about this stuff that
> I'd try to figure out why if I had a Mandrake system, but in the
> cosmic scheme of things I doubt it's important enough for anyone
> else to burn time on.

Well, I don't know about Mandrake, but I have glibc 2.1.94 here, and I
get

Python 2.0 (#104, Oct 15 2000, 15:47:19) 
[GCC 2.95.2 19991024 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import math
>>> math.sqrt(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: math range error
>>> math.exp(800)
inf
>>> math.exp(-800)
0.0

It turns that Tcl8.3 and Tk8.3, on my system, link with -lieee. That
is implemented as

_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;

in this version of glibc, which in turn changes the behaviour of 

double __exp(double x)		/* wrapper exp */
{
	double z;
	z = __ieee754_exp(x);
	if(_LIB_VERSION == _IEEE_) return z;
	if(__finite(x)) {
	    if(x>o_threshold)
	        return __kernel_standard(x,x,6); /* exp overflow */
	    else if(x<u_threshold)
	        return __kernel_standard(x,x,7); /* exp underflow */
	}
	return z;
}

As a rationale for linking with -lieee, the Tcl/Tk configure.in offers

#       Also, Linux requires the "ieee" library for math to
#       work right (and it must appear before "-lm").

Without testing, it seems that this would give some interesting
consequences on installations where Tkinter is a shared module: the
outcome of these functions could depend on whether Tkinter is imported
or not. I can't produce such a scenario with the BeOpen binaries on a
RedHat systems; the Tcl 8.0 RPMs of RedHat include the
tcltk-8.0-ieee.patch, which removes the line 

AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])

from both Tcl's and Tk's configure.in.

Of course, the problem is not restricted to Tcl: any extension module
that links with a shared library that includes libieee.a would change
the behaviour of Python's math functions.

Regards,
Martin