[New-bugs-announce] [issue3682] test_math: math.log(-ninf) fails to raise exception on OpenBSD

Damien Miller report at bugs.python.org
Tue Aug 26 02:03:48 CEST 2008

New submission from Damien Miller <djmdjm at users.sourceforge.net>:


On OpenBSD 4.4, the test_math.py regression test fails with the following:

Traceback (most recent call last):
  File "Lib/test/test_math.py", line 419, in testLog
    self.assertRaises(ValueError, math.log, NINF)
AssertionError: ValueError not raised

This is because libm's log function does not return NaN when passed
-INFINITY. It returns -INFINITY and sets EDOM. This behaviour seems to
be permitted by the C99 spec (ISO/IEC 9899:1999):

> 7.12.1 Treatment of error conditions
> paragraph2:
> ... On a domain error, the function returns an implementation-defined
> value; if the integer expression math_errhandling & MATH_ERRNO is 
> nonzero, the integer expression errno acquires the value EDOM; 

in mathmodule.c:math_1() errno seems to be deliberately ignored when the
result is infinite. The attached patch modified math_1() to retain EDOM
errors for infinite results.

components: Library (Lib)
files: patch-Modules_mathmodule_c
messages: 71963
nosy: djmdjm
severity: normal
status: open
title: test_math: math.log(-ninf) fails to raise exception on OpenBSD
versions: Python 2.6
Added file: http://bugs.python.org/file11258/patch-Modules_mathmodule_c

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list