STINNER Victor added the comment:
Guido van Rossum added the comment:
Should inf and nan be added to cmath too? It has e and pi and isnan() and
isinf()...
Also complex(0, math.nan) a value that is printed as nanj and
complex(nanj) parses and returns such a value, so the point could be
Mark Dickinson added the comment:
Opened issue #23229.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
___
___
Python-bugs-list mailing
Mark Dickinson added the comment:
Should inf and nan be added to cmath too?
Hmm; probably, yes. I'll open an issue.
so the point could be made that there should be a constant named complex.nanj
Yes, I suppose it could (along with infj, of course). I don't like it much,
and I suspect it
Guido van Rossum added the comment:
Should inf and nan be added to cmath too? It has e and pi and isnan() and
isinf()...
Also complex(0, math.nan) a value that is printed as nanj and complex(nanj)
parses and returns such a value, so the point could be made that there should
be a constant
Mark Dickinson added the comment:
Committed. Thanks for all the helpful review comments!
--
resolution: - fixed
stage: needs patch - resolved
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
Roundup Robot added the comment:
New changeset cf4bf577749c by Mark Dickinson in branch 'default':
Issue #23185: add math.inf and math.nan constants.
https://hg.python.org/cpython/rev/cf4bf577749c
--
nosy: +python-dev
___
Python tracker
Changes by Ethan Furman et...@stoneleaf.us:
--
nosy: +eric.smith, lemburg, rhettinger, stutzbach
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
___
STINNER Victor added the comment:
2015-01-09 8:16 GMT+01:00 Serhiy Storchaka rep...@bugs.python.org:
May be make math.inf and math.nan special objects so that for all x (except
inf and nan):
What do you mean? Implement a subtype of float and override some methods?
x math.inf
x -math.inf
Serhiy Storchaka added the comment:
May be make math.inf and math.nan special objects so that for all x (except inf
and nan):
x math.inf
x -math.inf
not (x math.nan)
not (x math.nan)
--
___
Python tracker rep...@bugs.python.org
STINNER Victor added the comment:
Except of my small suggestion on the doc (see the review), math_inf_nan4.patch
looks good to me.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
___
Mark Dickinson added the comment:
I have an updated patch taking into account the most recent review comments
(for which thanks!), but it's at home; I'll upload it this evening (UTC+00:00).
--
___
Python tracker rep...@bugs.python.org
Mark Dickinson added the comment:
New patch, addressing review comments.
--
Added file: http://bugs.python.org/file37647/math_inf_nan4.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
Mark Dickinson added the comment:
One more patch, fixing a misplaced period.
--
Added file: http://bugs.python.org/file37635/math_inf_nan3.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
STINNER Victor added the comment:
History, perhaps? In any case, the sign of a NaN isn't useful information in
the same way that the sign of an infinity is. The IEEE 754 standard explicitly
refuses to attach any meaning to the sign bit of a NaN. And if we were aiming
for a full and
Changes by Berker Peksag berker.pek...@gmail.com:
--
components: +Library (Lib)
stage: - needs patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
___
Mark Dickinson added the comment:
Sounds good to me.
Do we add a math.neginf
IMO no: -inf should be fine.
--
nosy: +mark.dickinson
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
___
Mark Dickinson added the comment:
float(-inf) and -float(inf) have exactly the same IEEE 754 representation
Indeed: there's only one negative infinity (and only one positive infinity) in
IEEE 754 binary64 format.
--
___
Python tracker
Mark Dickinson added the comment:
Implementation suggestion: if possible, use the _Py_dg_stdnan and
_Py_dg_infinity functions from Python/dtoa.c. These are a little safer than
the Py_NAN and Py_HUGE_VAL macros, and will give results consistent with the
float(inf) and float(nan)
New submission from Ethan Furman:
Proposal:
math.nan = float('nan')
math.inf = float('inf')
Guido's approval:
https://mail.python.org/pipermail/python-ideas/2015-January/030775.html
Followup question:
Do we add a math.neginf, or somesuch, for float('-inf')? Or just use
STINNER Victor added the comment:
Do we add a math.neginf, or somesuch, for float('-inf')? Or just use
-math.inf?
I would prefer to only add inf.
It looks like float(-inf) and -float(inf) have exactly the same IEEE 754
representation (at least on my x86_64 CPU):
struct.pack(d,
Mark Dickinson added the comment:
Why does Python return the same representation for positive and negative NaN?
History, perhaps? In any case, the sign of a NaN isn't useful information in
the same way that the sign of an infinity is. The IEEE 754 standard explicitly
refuses to attach any
Serhiy Storchaka added the comment:
There are several different NaNs.
x = struct.unpack('d', b'\x00\x00\x00\x00\x00\x00\xf8\x7f')[0]
x
nan
x == x
False
struct.pack('d', x)
b'\x00\x00\x00\x00\x00\x00\xf8\x7f'
x = struct.unpack('d', b'\x00\x00\x00\x00\x00\x00\xf9\x7f')[0]
x
nan
x == x
Mark Dickinson added the comment:
but 0*inf and inf-inf return values with the same representation as
float('-nan'), not float('nan')
Right: that's because Intel's default NaN (i.e., the float it produces as a
result of any invalid operation) has its sign bit set.
--
Mark Dickinson added the comment:
By tweaking the grammar we can have math.-inf.
RRGH!
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
___
Antoine Pitrou added the comment:
By tweaking the grammar we can have math.-inf.
--
nosy: +pitrou
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
___
Mark Dickinson added the comment:
Here's a patch.
--
assignee: - mark.dickinson
keywords: +patch
Added file: http://bugs.python.org/file37633/math_inf_nan.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23185
Mark Dickinson added the comment:
Thanks for the review comments. Here's an updated patch taking the review
comments into account (and fixing the spelling of PY_NAN, which should have
been Py_NAN).
--
Added file: http://bugs.python.org/file37634/math_inf_nan2.patch
STINNER Victor added the comment:
Oh, NaN can be signed?
struct.pack(d, float(nan))
b'\x00\x00\x00\x00\x00\x00\xf8\x7f'
struct.pack(d, float(-nan))
b'\x00\x00\x00\x00\x00\x00\xf8\xff'
struct.pack(d, -float(nan))
b'\x00\x00\x00\x00\x00\x00\xf8\xff'
struct.pack(d, -float(-nan))
28 matches
Mail list logo