This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sys.maxfloat patch
Type: Stage:
Components: Interpreter Core Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, gvanrossum, mark.dickinson
Priority: normal Keywords: patch

Created on 2007-12-01 01:22 by christian.heimes, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
trunk_maxfloat.patch christian.heimes, 2007-12-01 01:22
Messages (9)
msg58037 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-01 01:22
Currently Python has no information about the maximum and minimum value
of a float. The patch adds a dict with all important information to sys:

>>> pprint.pprint(sys.maxfloat)
{'dig': 15,
 'epsilon': 2.2204460492503131e-16,
 'mant_dig': 53,
 'max': 1.7976931348623157e+308,
 'max_10_exp': 308,
 'max_exp': 1024,
 'min': 2.2250738585072014e-308,
 'min_10_exp': -307,
 'min_exp': -1021,
 'radix': 2,
 'rounds': 1}

The patch compiles on Linux and Windows.
msg58038 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-12-01 01:25
I'd suggest giving it a different name, maybe float_info.  sys.maxfloat
suggests the value is a float, like sys.maxint and sys.maxunicode.
msg58041 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-01 11:24
Applied in r59254.

I've moved the code to floatobject.c/h and added PyFloat_GetMax() and
PyFloat_GetMin(), too. The intobject.c file has a similar function.
msg58051 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2007-12-01 15:55
A (probably stupid) question:  what's supposed to happen on platforms that 
don't define things like DBL_MAX_10_EXP, which isn't part of ANSI C89?  Or 
are there no such platforms?
msg58053 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-01 16:03
I've checked all major platforms before committing the patch. They all
have a float.h with the information available. Do you know of a platform
where this information isn't available? I could add a lot of #ifdef but
I don't feel like bloating the code unless it is necessary.
msg58054 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2007-12-01 16:17
No, I don't know of any platforms that don't define these constants.
msg58055 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2007-12-01 16:37
And it looks as though DBL_MAX_10_EXP *is* part of ANSI C anyway...  I 
shouldn't have assumed that just because it's not in Kernighan and Ritchie 
(2nd edition) it doesn't exist...  Apologies.
msg58062 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-01 18:06
Thanks for checking it out for me! Do you have a reliable online source
for the ANSI C89 standard? I'm usually using the GNU C Library docs but
the site doesn't list what's available in C89.
msg58075 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2007-12-02 01:17
The site that persuaded me about DBL_MAX_10_EXP was 

http://www.schweikhardt.net/identifiers.html

Googling 'C89 draft' also turns up some potentially useful stuff.
History
Date User Action Args
2022-04-11 14:56:28adminsetgithub: 45875
2008-01-06 22:29:44adminsetkeywords: - py3k
versions: Python 2.6, Python 3.0
2007-12-02 01:17:16mark.dickinsonsetmessages: + msg58075
2007-12-01 18:06:09christian.heimessetmessages: + msg58062
2007-12-01 16:37:12mark.dickinsonsetmessages: + msg58055
2007-12-01 16:17:47mark.dickinsonsetmessages: + msg58054
2007-12-01 16:03:26christian.heimessetmessages: + msg58053
2007-12-01 15:55:43mark.dickinsonsetnosy: + mark.dickinson
messages: + msg58051
2007-12-01 11:24:11christian.heimessetstatus: open -> closed
resolution: fixed
messages: + msg58041
2007-12-01 01:25:17gvanrossumsetnosy: + gvanrossum
messages: + msg58038
2007-12-01 01:22:16christian.heimescreate