Dear list, I have written a module to simulate the machine representation of binary floating point numbers and their arithmetic. Values can be of arbitrary fixed precision or infinite precision, along the same lines as python's in-built decimal class. The code can be found here: http://www2.gsu.edu/~matrhc/binary.html
The design is loosely based on that decimal module, and the primary intended use of this module is educational. You can play with different IEEE 754 representations with different precisions and rounding modes, and compare with infinite precision Binary numbers. For instance, it is easy to explore machine epsilon, representation/rounding error using a much simpler format such as a 4-bit exponent and 6-bit mantissa. The usual arithmetic operations are permitted on these objects, as well as representations of their values in decimal or binary form. Default contexts for half, single, double, and quadruple IEEE 754 precision floats are provided. Binary integer classes are also provided, and some other utility functions for converting between decimal and binary string representations. The module is compatible with the numpy float classes and requires numpy to be installed. The source code is released under the BSD license, but I am amenable to other licensing ideas if there is interest in adapting the code for some other purpose. Full details of the functionality and known issues are in the module's docstring, and many examples of usage are in the accompanying file test_binary.py (which also acts to validate the common representations against the built-in floating point types). I look forward to hearing feedback, especially in case of bugs or suggestions for improvements. -Rob -- Robert H. Clewley, Ph. D. Assistant Professor Department of Mathematics and Statistics Georgia State University 720 COE, 30 Pryor St Atlanta, GA 30303, USA tel: 404-413-6420 fax: 404-413-6403 http://www2.gsu.edu/~matrhc http://brainsbehavior.gsu.edu/ <P><A HREF="http://www2.gsu.edu/~matrhc/binary.html">Binary 0.1</A> - Simulator of arbitrary fixed and infinite precision binary floating point. (12-Aug-08) -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html