New submission from Christian Heimes:
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.
----------
components: Interpreter Core
files: trunk_maxfloat.patch
keywords: patch, py3k
messages: 58037
nosy: tiran
priority: normal
severity: normal
status: open
title: sys.maxfloat patch
versions: Python 2.6, Python 3.0
Added file: http://bugs.python.org/file8840/trunk_maxfloat.patch
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1534>
__________________________________
Index: Python/sysmodule.c
===================================================================
--- Python/sysmodule.c (Revision 59248)
+++ Python/sysmodule.c (Arbeitskopie)
@@ -18,6 +18,7 @@
#include "code.h"
#include "frameobject.h"
#include "eval.h"
+#include <float.h>
#include "osdefs.h"
@@ -1045,7 +1046,37 @@
return shortbranch;
}
+#define SET_FLOAT_CONST(d, key, const) \
+ tmp = PyFloat_FromDouble(const); \
+ if (tmp == NULL) return NULL; \
+ if (PyDict_SetItemString(d, key, tmp)) return NULL; \
+ Py_DECREF(tmp)
+#define SET_INT_CONST(d, key, const) \
+ tmp = PyInt_FromLong(const); \
+ if (tmp == NULL) return NULL; \
+ if (PyDict_SetItemString(d, key, tmp)) return NULL; \
+ Py_DECREF(tmp)
+
PyObject *
+maxfloat(void)
+{
+ PyObject *d, *tmp;
+ d = PyDict_New();
+ SET_FLOAT_CONST(d, "max", DBL_MAX);
+ SET_INT_CONST(d, "max_exp", DBL_MAX_EXP);
+ SET_INT_CONST(d, "max_10_exp", DBL_MAX_10_EXP);
+ SET_FLOAT_CONST(d, "min", DBL_MIN);
+ SET_INT_CONST(d, "min_exp", DBL_MIN_EXP);
+ SET_INT_CONST(d, "min_10_exp", DBL_MIN_10_EXP);
+ SET_INT_CONST(d, "dig", DBL_DIG);
+ SET_INT_CONST(d, "mant_dig", DBL_MANT_DIG);
+ SET_FLOAT_CONST(d, "epsilon", DBL_EPSILON);
+ SET_INT_CONST(d, "radix", FLT_RADIX);
+ SET_INT_CONST(d, "rounds", FLT_ROUNDS);
+ return d;
+}
+
+PyObject *
_PySys_Init(void)
{
PyObject *m, *v, *sysdict;
@@ -1169,6 +1200,8 @@
PyInt_FromLong(PyInt_GetMax()));
SET_SYS_FROM_STRING("py3kwarning",
PyBool_FromLong(Py_Py3kWarningFlag));
+ SET_SYS_FROM_STRING("maxfloat",
+ maxfloat());
#ifdef Py_USING_UNICODE
SET_SYS_FROM_STRING("maxunicode",
PyInt_FromLong(PyUnicode_GetMax()));
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com