[Python-Dev] == on object tests identity in 3.x
steve+comp.lang.python at pearwood.info
Wed Jul 9 03:04:12 CEST 2014
On Tue, 08 Jul 2014 16:05:45 -0600, Ian Kelly wrote:
> On Tue, Jul 8, 2014 at 3:53 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> On Tue, Jul 8, 2014 at 2:10 PM, Anders J. Munch <2014 at jmunch.dk> wrote:
>>> Steven D'Aprano wrote:
>>>> - Keeping reflexivity for NANs would have implied some pretty nasty
>>>> things, e.g. if log(-3) == log(-5), then -3 == -5.
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> ValueError: math domain error
>>> You were perhaps referring to the log functions in C and Fortran, not
>>> The tradeoffs are different in those languages, so choices the
>>> IEEE-754 committee made with C and Fortran in mind may be less
>>> relevant for Python.
>>>>> import ctypes
>>>>> libm = ctypes.cdll.LoadLibrary("libm.so.6") log = libm.log
>>>>> log.argtypes = [ctypes.c_double]
>>>>> log.restype = ctypes.c_double
>>>>> log(-3) == log(-5)
> Also, numpy provides more control over floating-point error handling
> than straight Python does, and I think (but can't presently test) that
> numpy.log(-3) will return nan by default.
py> if numpy.log(-3) == numpy.log(-5):
... print "-3 == -5"
More information about the Python-list