Issue 1534: sys.maxfloat patch - Python tracker (original) (raw)
Created on 2007-12-01 01:22 by christian.heimes, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (9)
Author: Christian Heimes (christian.heimes) *
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.
Author: Guido van Rossum (gvanrossum) *
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.
Author: Christian Heimes (christian.heimes) *
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.
Author: Mark Dickinson (mark.dickinson) *
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?
Author: Christian Heimes (christian.heimes) *
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.
Author: Mark Dickinson (mark.dickinson) *
Date: 2007-12-01 16:17
No, I don't know of any platforms that don't define these constants.
Author: Mark Dickinson (mark.dickinson) *
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.
Author: Christian Heimes (christian.heimes) *
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.
Author: Mark Dickinson (mark.dickinson) *
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:28
admin
set
github: 45875
2008-01-06 22:29:44
admin
set
keywords: - py3k
versions: Python 2.6, Python 3.0
2007-12-02 01:17:16
mark.dickinson
set
messages: +
2007-12-01 18:06:09
christian.heimes
set
messages: +
2007-12-01 16:37:12
mark.dickinson
set
messages: +
2007-12-01 16:17:47
mark.dickinson
set
messages: +
2007-12-01 16:03:26
christian.heimes
set
messages: +
2007-12-01 15:55:43
mark.dickinson
set
nosy: + mark.dickinson
messages: +
2007-12-01 11:24:11
christian.heimes
set
status: open -> closed
resolution: fixed
messages: +
2007-12-01 01:25:17
gvanrossum
set
nosy: + gvanrossum
messages: +
2007-12-01 01:22:16
christian.heimes
create