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)

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: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