Skip to content

Commit 9385266

Browse files
committed
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 python#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. ........
1 parent 8598422 commit 9385266

10 files changed

Lines changed: 144 additions & 20 deletions

File tree

Doc/c-api/concrete.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,23 @@ Floating Point Objects
499499
without error checking.
500500

501501

502+
.. cfunction:: PyObject* PyFloat_GetInfo(void)
503+
504+
Return a :ctype:`PyDictObject` object which contains information about the
505+
precision, minimum and maximum values of a float. It's a thin wrapper
506+
around the header file :file:`float.h`.
507+
508+
509+
.. cfunction:: double PyFloat_GetMax(void)
510+
511+
Return the maximum representable finite float *DBL_MAX* as C :ctype:`double`.
512+
513+
514+
.. cfunction:: double PyFloat_GetMin(void)
515+
516+
Return the minimum normalized positive float *DBL_MIN* as C :ctype:`double`.
517+
518+
502519
.. _complexobjects:
503520

504521
Complex Number Objects

Doc/library/os.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,17 @@ by file descriptors.
422422
Change the mode of the file given by *fd* to the numeric *mode*. See the docs
423423
for :func:`chmod` for possible values of *mode*. Availability: Unix.
424424

425+
.. versionadded:: 2.6
426+
425427

426428
.. function:: fchown(fd, uid, gid)
427429

428430
Change the owner and group id of the file given by *fd* to the numeric *uid*
429431
and *gid*. To leave one of the ids unchanged, set it to -1.
430432
Availability: Unix.
431433

434+
.. versionadded:: 2.6
435+
432436

433437
.. function:: fdatasync(fd)
434438

@@ -488,13 +492,6 @@ by file descriptors.
488492
tty(-like) device, else ``False``. Availability: Macintosh, Unix.
489493

490494

491-
.. function:: lchmod(path, mode)
492-
493-
Change the mode of *path* to the numeric *mode*. If path is a symlink, this
494-
affects the symlink rather than the target. See the docs for :func:`chmod`
495-
for possible values of *mode*. Availability: Unix.
496-
497-
498495
.. function:: lseek(fd, pos, how)
499496

500497
Set the current position of file descriptor *fd* to position *pos*, modified by
@@ -800,6 +797,15 @@ Files and Directories
800797
follow symbolic links. Availability: Unix.
801798

802799

800+
.. function:: lchmod(path, mode)
801+
802+
Change the mode of *path* to the numeric *mode*. If path is a symlink, this
803+
affects the symlink rather than the target. See the docs for :func:`chmod`
804+
for possible values of *mode*. Availability: Unix.
805+
806+
.. versionadded:: 2.6
807+
808+
803809
.. function:: lchown(path, uid, gid)
804810

805811
Change the owner and group id of *path* to the numeric *uid* and gid. This

Doc/library/sys.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,48 @@ always available.
184184
error occurs.
185185

186186

187+
.. data:: float_info
188+
189+
A dict holding information about the float type. It contains low level
190+
information about the precision and internal representation. Please study
191+
your system's :file:`float.h` for more information.
192+
193+
+---------------------+--------------------------------------------------+
194+
| key | explanation |
195+
+=====================+==================================================+
196+
| :const:`epsilon` | Difference between 1 and the next representable |
197+
| | floating point number |
198+
+---------------------+--------------------------------------------------+
199+
| :const:`dig` | digits (see :file:`float.h`) |
200+
+---------------------+--------------------------------------------------+
201+
| :const:`mant_dig` | mantissa digits (see :file:`float.h`) |
202+
+---------------------+--------------------------------------------------+
203+
| :const:`max` | maximum representable finite float |
204+
+---------------------+--------------------------------------------------+
205+
| :const:`max_exp` | maximum int e such that radix**(e-1) is in the |
206+
| | range of finite representable floats |
207+
+---------------------+--------------------------------------------------+
208+
| :const:`max_10_exp` | maximum int e such that 10**e is in the |
209+
| | range of finite representable floats |
210+
+---------------------+--------------------------------------------------+
211+
| :const:`min` | Minimum positive normalizer float |
212+
+---------------------+--------------------------------------------------+
213+
| :const:`min_exp` | minimum int e such that radix**(e-1) is a |
214+
| | normalized float |
215+
+---------------------+--------------------------------------------------+
216+
| :const:`min_10_exp` | minimum int e such that 10**e is a normalized |
217+
| | float |
218+
+---------------------+--------------------------------------------------+
219+
| :const:`radix` | radix of exponent |
220+
+---------------------+--------------------------------------------------+
221+
| :const:`rounds` | addition rounds (see :file:`float.h`) |
222+
+---------------------+--------------------------------------------------+
223+
224+
.. note::
225+
226+
The information in the table is simplified.
227+
228+
187229
.. function:: getcheckinterval()
188230

189231
Return the interpreter's "check interval"; see :func:`setcheckinterval`.

Include/floatobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
2121
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
2222
#define PyFloat_CheckExact(op) (Py_Type(op) == &PyFloat_Type)
2323

24+
PyAPI_FUNC(double) PyFloat_GetMax(void);
25+
PyAPI_FUNC(double) PyFloat_GetMin(void);
26+
PyAPI_FUNC(PyObject *) PyFloat_GetInfo(void);
27+
2428
/* Return Python float from string PyObject. */
2529
PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*);
2630

Lib/test/regrtest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,12 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
699699
fs = warnings.filters[:]
700700
ps = copy_reg.dispatch_table.copy()
701701
pic = sys.path_importer_cache.copy()
702-
abcs = {obj: obj._abc_registry.copy()
703-
for abc in [getattr(_abcoll, a) for a in _abcoll.__all__
704-
if issubclass(getattr(_abcoll, a), _Abstract)]
705-
for obj in abc.__subclasses__() + [abc]}
702+
abcs = {}
703+
for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]:
704+
if not isinstance(abc, _Abstract):
705+
continue
706+
for obj in abc.__subclasses__() + [abc]:
707+
abcs[obj] = obj._abc_registry.copy()
706708

707709
if indirect_test:
708710
def run_the_test():

Lib/test/test_sys.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ def test_attributes(self):
279279
self.assert_(isinstance(sys.copyright, str))
280280
self.assert_(isinstance(sys.exec_prefix, str))
281281
self.assert_(isinstance(sys.executable, str))
282+
self.assert_(isinstance(sys.float_info, dict))
283+
self.assertEqual(len(sys.float_info), 11)
282284
self.assert_(isinstance(sys.hexversion, int))
283285
self.assert_(isinstance(sys.maxint, int))
284286
self.assert_(isinstance(sys.maxunicode, int))

Objects/floatobject.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "formatter_unicode.h"
1010

1111
#include <ctype.h>
12+
#include <float.h>
1213

1314
#if !defined(__STDC__)
1415
extern double fmod(double, double);
@@ -48,6 +49,52 @@ fill_free_list(void)
4849
return p + N_FLOATOBJECTS - 1;
4950
}
5051

52+
double
53+
PyFloat_GetMax(void)
54+
{
55+
return DBL_MAX;
56+
}
57+
58+
double
59+
PyFloat_GetMin(void)
60+
{
61+
return DBL_MIN;
62+
}
63+
64+
PyObject *
65+
PyFloat_GetInfo(void)
66+
{
67+
PyObject *d, *tmp;
68+
69+
#define SET_FLOAT_CONST(d, key, const) \
70+
tmp = PyFloat_FromDouble(const); \
71+
if (tmp == NULL) return NULL; \
72+
if (PyDict_SetItemString(d, key, tmp)) return NULL; \
73+
Py_DECREF(tmp)
74+
#define SET_INT_CONST(d, key, const) \
75+
tmp = PyInt_FromLong(const); \
76+
if (tmp == NULL) return NULL; \
77+
if (PyDict_SetItemString(d, key, tmp)) return NULL; \
78+
Py_DECREF(tmp)
79+
80+
d = PyDict_New();
81+
82+
SET_FLOAT_CONST(d, "max", DBL_MAX);
83+
SET_INT_CONST(d, "max_exp", DBL_MAX_EXP);
84+
SET_INT_CONST(d, "max_10_exp", DBL_MAX_10_EXP);
85+
SET_FLOAT_CONST(d, "min", DBL_MIN);
86+
SET_INT_CONST(d, "min_exp", DBL_MIN_EXP);
87+
SET_INT_CONST(d, "min_10_exp", DBL_MIN_10_EXP);
88+
SET_INT_CONST(d, "dig", DBL_DIG);
89+
SET_INT_CONST(d, "mant_dig", DBL_MANT_DIG);
90+
SET_FLOAT_CONST(d, "epsilon", DBL_EPSILON);
91+
SET_INT_CONST(d, "radix", FLT_RADIX);
92+
SET_INT_CONST(d, "rounds", FLT_ROUNDS);
93+
94+
return d;
95+
}
96+
97+
5198
PyObject *
5299
PyFloat_FromDouble(double fval)
53100
{

PC/pyconfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ compiler specific". Therefore, these should be very rare.
2323
2424
2525
NOTE: The following symbols are deprecated:
26-
NT, WIN32, USE_DL_EXPORT, USE_DL_IMPORT, DL_EXPORT, DL_IMPORT
26+
NT, USE_DL_EXPORT, USE_DL_IMPORT, DL_EXPORT, DL_IMPORT
2727
MS_CORE_DLL.
2828
29+
WIN32 is still required for the locale module.
30+
2931
*/
3032

3133
#ifdef _WIN32_WCE

PCbuild9/pythoncore.vcproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
Name="VCCLCompilerTool"
4545
AdditionalOptions="/Zm200 "
4646
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
47-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
47+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
4848
RuntimeLibrary="2"
4949
/>
5050
<Tool
@@ -119,7 +119,7 @@
119119
Name="VCCLCompilerTool"
120120
AdditionalOptions="/Zm200 "
121121
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
122-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
122+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
123123
RuntimeLibrary="2"
124124
/>
125125
<Tool
@@ -197,7 +197,7 @@
197197
InlineFunctionExpansion="0"
198198
EnableIntrinsicFunctions="false"
199199
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
200-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
200+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
201201
RuntimeLibrary="3"
202202
/>
203203
<Tool
@@ -275,7 +275,7 @@
275275
InlineFunctionExpansion="0"
276276
EnableIntrinsicFunctions="false"
277277
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
278-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
278+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
279279
RuntimeLibrary="3"
280280
/>
281281
<Tool
@@ -349,7 +349,7 @@
349349
Name="VCCLCompilerTool"
350350
AdditionalOptions="/Zm200 "
351351
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
352-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
352+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
353353
RuntimeLibrary="2"
354354
/>
355355
<Tool
@@ -424,7 +424,7 @@
424424
Name="VCCLCompilerTool"
425425
AdditionalOptions="/Zm200 "
426426
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
427-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
427+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
428428
RuntimeLibrary="2"
429429
/>
430430
<Tool
@@ -499,7 +499,7 @@
499499
Name="VCCLCompilerTool"
500500
AdditionalOptions="/Zm200 "
501501
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
502-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
502+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
503503
RuntimeLibrary="2"
504504
/>
505505
<Tool
@@ -574,7 +574,7 @@
574574
Name="VCCLCompilerTool"
575575
AdditionalOptions="/Zm200 "
576576
AdditionalIncludeDirectories="..\Python;..\Modules\zlib"
577-
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED"
577+
PreprocessorDefinitions="_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;WIN32"
578578
RuntimeLibrary="2"
579579
/>
580580
<Tool

Python/sysmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,8 @@ _PySys_Init(void)
10821082
PyInt_FromLong(PyInt_GetMax()));
10831083
SET_SYS_FROM_STRING("maxsize",
10841084
PyInt_FromSsize_t(PY_SSIZE_T_MAX));
1085+
SET_SYS_FROM_STRING("float_info",
1086+
PyFloat_GetInfo());
10851087
SET_SYS_FROM_STRING("maxunicode",
10861088
PyInt_FromLong(PyUnicode_GetMax()));
10871089
SET_SYS_FROM_STRING("builtin_module_names",

0 commit comments

Comments
 (0)