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

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.

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.

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.

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?

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.

No, I don't know of any platforms that don't define these constants.

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.

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.

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.
versions: Python 2.6, Python 3.0
messages: + msg58051
resolution: fixed
messages: + msg58041
messages: + msg58038