[issue23185] add inf and nan to math module

2015-01-13 Thread Mark Dickinson
Mark Dickinson added the comment: Opened issue #23229. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https

[issue23185] add inf and nan to math module

2015-01-13 Thread Mark Dickinson
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

[issue23185] add inf and nan to math module

2015-01-13 Thread STINNER Victor
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 cou

[issue23185] add inf and nan to math module

2015-01-12 Thread Guido van Rossum
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

[issue23185] add inf and nan to math module

2015-01-11 Thread Mark Dickinson
Mark Dickinson added the comment: Committed. Thanks for all the helpful review comments! -- resolution: -> fixed stage: needs patch -> resolved status: open -> closed ___ Python tracker __

[issue23185] add inf and nan to math module

2015-01-11 Thread Roundup Robot
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

[issue23185] add inf and nan to math module

2015-01-10 Thread Ethan Furman
Changes by Ethan Furman : -- nosy: +eric.smith, lemburg, rhettinger, stutzbach ___ Python tracker ___ ___ Python-bugs-list mailing lis

[issue23185] add inf and nan to math module

2015-01-09 Thread STINNER Victor
STINNER Victor added the comment: 2015-01-09 8:16 GMT+01:00 Serhiy Storchaka : > 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 It's already th

[issue23185] add inf and nan to math module

2015-01-08 Thread Serhiy Storchaka
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

[issue23185] add inf and nan to math module

2015-01-08 Thread STINNER Victor
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 ___

[issue23185] add inf and nan to math module

2015-01-08 Thread Mark Dickinson
Mark Dickinson added the comment: New patch, addressing review comments. -- Added file: http://bugs.python.org/file37647/math_inf_nan4.patch ___ Python tracker ___ __

[issue23185] add inf and nan to math module

2015-01-08 Thread Mark Dickinson
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 _

[issue23185] add inf and nan to math module

2015-01-07 Thread STINNER Victor
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 faithfu

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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 ___ __

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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 __

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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. -- __

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
Mark Dickinson added the comment: > By tweaking the grammar we can have math.-inf. RRGH! -- ___ Python tracker ___ ___ Python-bug

[issue23185] add inf and nan to math module

2015-01-07 Thread Antoine Pitrou
Antoine Pitrou added the comment: By tweaking the grammar we can have math.-inf. -- nosy: +pitrou ___ Python tracker ___ ___ Python-bu

[issue23185] add inf and nan to math module

2015-01-07 Thread Serhiy Storchaka
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

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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

[issue23185] add inf and nan to math module

2015-01-07 Thread STINNER Victor
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", -fl

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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") constructi

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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

[issue23185] add inf and nan to math module

2015-01-07 Thread Mark Dickinson
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 ___

[issue23185] add inf and nan to math module

2015-01-07 Thread Berker Peksag
Changes by Berker Peksag : -- components: +Library (Lib) stage: -> needs patch ___ Python tracker ___ ___ Python-bugs-list mailing li

[issue23185] add inf and nan to math module

2015-01-07 Thread STINNER Victor
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

[issue23185] add inf and nan to math module

2015-01-07 Thread Ethan Furman
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 -math.inf?