Author noam
Recipients noam
Date 2007-12-10.19:13:25
SpamBayes Score 0.0131176
Marked as misclassified No
Message-id <>
The current float repr() always calculates the 17 first digits of the
decimal representation of a float, and displays all of them (discarding
trailing zeros). This is a simple method for making sure that
eval(repr(f)) == f. However, many times it results in a long string,
where a shorter string would have sufficed. For example, currently
repr(1.1) is '1.1000000000000001', where obviously '1.1' would have been
good enough, and much easier to read.

This patch implements an algorithm for finding the shortest string that
will evaluate to the right number. It is based on the code from, and also on the
floating-point formatting function of TCL, Tcl_PrintDouble.

The patch also adds a test case, which takes a long list of floating
point numbers, created especially for testing binary to decimal
conversion, and makes sure that eval(repr(f)) == f. See
floating_points.txt for the source of the list.
File name Uploaded
short_float_repr.diff noam, 2007-12-10.19:13:25
Date User Action Args
2007-12-10 19:13:27noamsetspambayes_score: 0.0131176 -> 0.0131176
recipients: + noam
2007-12-10 19:13:27noamsetspambayes_score: 0.0131176 -> 0.0131176
messageid: <>
2007-12-10 19:13:26noamlinkissue1580 messages
2007-12-10 19:13:25noamcreate