summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-12-01 12:22:32 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-12-01 12:22:32 (GMT)
commit938526609f4bd3af2ab9660fa57065cd77674388 (patch)
treea6772bc55e731e38a6f092d497575f99a207ac44 /Objects
parent85984227ab7bc6b0625a897be49a4677c4f0eb47 (diff)
downloadcpython-938526609f4bd3af2ab9660fa57065cd77674388.zip
cpython-938526609f4bd3af2ab9660fa57065cd77674388.tar.gz
cpython-938526609f4bd3af2ab9660fa57065cd77674388.tar.bz2
Merged revisions 59245-59254 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59245 | georg.brandl | 2007-11-30 23:04:45 +0100 (Fri, 30 Nov 2007) | 2 lines Move lchmod() docs to correct place, and add versionadded tags. ........ r59249 | christian.heimes | 2007-11-30 23:36:10 +0100 (Fri, 30 Nov 2007) | 2 lines Backport of -r59242:59246 from py3k Fixed problem with regrtest caused by the additional of objects to _abcoll. ........ r59253 | christian.heimes | 2007-12-01 02:03:20 +0100 (Sat, 01 Dec 2007) | 1 line Although pyconfig.h claims that WIN32 is obsolete it is still required for the locale module. locale.getdefaultlocale() fails silently w/o the WIN32 macro. ........ r59254 | christian.heimes | 2007-12-01 12:20:10 +0100 (Sat, 01 Dec 2007) | 3 lines Feature #1534 Added PyFloat_GetMax(), PyFloat_GetMin() and PyFloat_GetInfo() to the float API. Added a dictionary sys.float_info with information about the internal floating point type to the sys module. ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 3ef44f6..d3b7c9e 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -9,6 +9,7 @@
#include "formatter_unicode.h"
#include <ctype.h>
+#include <float.h>
#if !defined(__STDC__)
extern double fmod(double, double);
@@ -48,6 +49,52 @@ fill_free_list(void)
return p + N_FLOATOBJECTS - 1;
}
+double
+PyFloat_GetMax(void)
+{
+ return DBL_MAX;
+}
+
+double
+PyFloat_GetMin(void)
+{
+ return DBL_MIN;
+}
+
+PyObject *
+PyFloat_GetInfo(void)
+{
+ PyObject *d, *tmp;
+
+#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)
+
+ 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 *
PyFloat_FromDouble(double fval)
{