Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74214 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2014-07-08 16:05 -0600 |
| Last post | 2014-07-09 01:04 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [Python-Dev] == on object tests identity in 3.x Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-08 16:05 -0600
Re: [Python-Dev] == on object tests identity in 3.x Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-09 01:04 +0000
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-07-08 16:05 -0600 |
| Subject | Re: [Python-Dev] == on object tests identity in 3.x |
| Message-ID | <mailman.11665.1404857194.18130.python-list@python.org> |
On Tue, Jul 8, 2014 at 3:53 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Tue, Jul 8, 2014 at 2:10 PM, Anders J. Munch <2014@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.
>>
>>
>>>>> log(-3)
>> 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
>> math.log?
>> 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)
> nan
>>>> log(-5)
> nan
>>>> log(-3) == log(-5)
> False
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.
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-07-09 01:04 +0000 |
| Message-ID | <53bc950c$0$29995$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #74214 |
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@gmail.com> wrote:
>> On Tue, Jul 8, 2014 at 2:10 PM, Anders J. Munch <2014@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.
>>>
>>>
>>>>>> log(-3)
>>> 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
>>> math.log?
>>> 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)
>> nan
>>>>> log(-5)
>> nan
>>>>> log(-3) == log(-5)
>> False
>
> 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.
Correct:
py> numpy.log(-3)
nan
py> if numpy.log(-3) == numpy.log(-5):
... print "-3 == -5"
...
py>
--
Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web