classification
Title: Document the meaning of FLT_ROUNDS constants for sys.float_info
Type: Stage: commit review
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: christian.heimes, docs@python, ezio.melotti, mark.dickinson, python-dev, rhettinger
Priority: normal Keywords: patch

Created on 2011-06-02 19:47 by rhettinger, last changed 2011-11-19 16:28 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
issue12245.patch mark.dickinson, 2011-06-25 09:34 review
Messages (6)
msg137493 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-06-02 19:47
>>> sys.float_info.rounds
1
msg137647 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-06-04 15:14
float_info.rounds is a bit of an odd fish, and I think it was probably a mistake to include it in sys.float_info in the first place.

All the other float_info fields relate to parameters of the floating-point format, which is fixed, useful information.  In contrast, float_info.rounds gives information about the current FPU settings, which are variable.  Moreover, it doesn't do that very well:  all it does is give information about the FPU settings at the time that Python was compiled, which isn't really very helpful (and perhaps not even that:  it reports the value of FLT_ROUNDS, which may not even reflect those FPU settings accurately).  I wouldn't mind seeing this field fade quietly into obscurity.

FWIW, the value is taken from C's FLT_ROUNDS, and its interpretation is *supposed* to be the following (C99 5.2.4.2.2, para 7):

  -1:  The compiler was unable to determine rounding mode.
   0:  Round towards zero.
   1:  Round to nearest (this is the most likely value for
       float_info.rounds on common platforms).
   2:  Round towards positive infinity
   3:  Round towards negative infinity.
msg139031 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-06-25 09:25
> all it does is give information about the FPU settings at the time that
> Python was compiled

Hmm.  It's actually a bit better than that:  as far as I can tell, it reflects the value of FLT_ROUNDS at the time that Python is started (when the sys module is initialized).  OTOH, FLT_ROUNDS on my machine is #define'd to be 1, in violation of the C standards.
msg139032 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-06-25 09:34
Patch that elaborates a bit on the meaning of sys.float_info.rounds.
msg147321 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-11-08 23:38
LGTM
msg147949 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-19 16:27
New changeset de1ecda2afa2 by Mark Dickinson in branch '2.7':
Issue #12245: Document sys.float_info.rounds better.
http://hg.python.org/cpython/rev/de1ecda2afa2

New changeset 795c184b0282 by Mark Dickinson in branch '3.2':
Issue #12245: Document sys.float_info.rounds better.
http://hg.python.org/cpython/rev/795c184b0282

New changeset 5e45dfc421e4 by Mark Dickinson in branch 'default':
Issue #12245 merge.
http://hg.python.org/cpython/rev/5e45dfc421e4
History
Date User Action Args
2011-11-19 16:28:16mark.dickinsonsetstatus: open -> closed
resolution: fixed
2011-11-19 16:27:50python-devsetnosy: + python-dev
messages: + msg147949
2011-11-08 23:38:58ezio.melottisetnosy: + ezio.melotti

messages: + msg147321
stage: commit review
2011-06-25 09:34:25mark.dickinsonsetfiles: + issue12245.patch
keywords: + patch
messages: + msg139032
2011-06-25 09:25:52mark.dickinsonsetmessages: + msg139031
2011-06-04 16:19:09mark.dickinsonsetassignee: docs@python -> mark.dickinson
2011-06-04 16:18:06mark.dickinsonsetnosy: + christian.heimes
2011-06-04 15:14:42mark.dickinsonsetnosy: + mark.dickinson
messages: + msg137647
2011-06-02 19:47:10rhettingercreate