Mark Summerfield added the comment:
On 2007-12-17, Christian Heimes wrote:
> Christian Heimes added the comment:
>
> Hi Mark!
>
> In general the patch is fine but it has some small issues.
>
> * Your patches are all reversed. They remove (-) the new lines instead
> of adding (+) them. Why aren't you using svn diff > file.patch?
I didn't know about that. Have now used it.
> * You are mixing tabs with spaces. All 2.6 C files and most 3.0 C files
> are still using tabs.
Okay, have now switched to tabs.
> * You forgot about %f. For large values the format characters f and F
> are using the exponent display, too "%f" % 1e60 == '1e+60'
Good point; I now search for 'e' or 'E' in any number.
> * You cannot assume that char is unsigned. Use Py_CHARMAP(char) instead.
> I think that you can make the code more readable when you do format_char
> = tolower(Py_CHARMAP(format_char)); first.
I don't refer to format_char any more.
> * The code is not C89 conform. The standards dictate that you cannot
> declare a var in the middle of a block. New var must be declared right
> after the {
I didn't know that. I've now moved the variable declarations.
I've attached the diff you asked for, plus a diff for the test_float.py
file -- and I've done the changes in relation to 2.6 trunk since there's
nothing 3.0-specific.
Hope this is now okay.
Added file: http://bugs.python.org/file8983/pystrtod.c.diff
Added file: http://bugs.python.org/file8984/test_float.py.diff
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1600>
__________________________________
Index: Python/pystrtod.c
===================================================================
--- Python/pystrtod.c (revision 59545)
+++ Python/pystrtod.c (working copy)
@@ -238,6 +238,30 @@
}
}
+ /* Ensure that the exponent is at least 3 digits,
+ providing the buffer is large enough for the extra zeros. */
+ p = buffer;
+ while (*p && *p != 'e' && *p != 'E')
+ ++p;
+ if (*p && (*(p + 1) == '-' || *(p + 1) == '+')) {
+ char *start = p + 2;
+ int exponent_digit_count = 0;
+ int zeros = 0;
+ p += 2;
+ while (*p && isdigit((unsigned char)*p)) {
+ ++p;
+ ++exponent_digit_count;
+ }
+ zeros = 3 - exponent_digit_count;
+ if (exponent_digit_count && zeros > 0 &&
+ start + zeros + exponent_digit_count + 1
+ < buffer + buf_len) {
+ p = start;
+ memmove(p + zeros, p, exponent_digit_count + 1);
+ memset(p, '0', zeros);
+ }
+ }
+
return buffer;
}
Index: Lib/test/test_float.py
===================================================================
--- Lib/test/test_float.py (revision 59545)
+++ Lib/test/test_float.py (working copy)
@@ -129,12 +129,29 @@
floats_file.close()
+class StrFormatETestCase(unittest.TestCase):
+ def test_str_format_e(self):
+ self.assertEqual("1.234e+009", "%.3e" %1.23405e+9)
+ self.assertEqual("1.234e-009", "%.3e" %1.23405e-9)
+ self.assertEqual("1.234E+009", "%.3E" %1.23405e+9)
+ self.assertEqual("1.234E-009", "%.3E" %1.23405e-9)
+ self.assertEqual("1.234e+027", "%.3e" %1.23405e+27)
+ self.assertEqual("1.234e-027", "%.3e" %1.23405e-27)
+ self.assertEqual("1.234E+027", "%.3E" %1.23405e+27)
+ self.assertEqual("1.234E-027", "%.3E" %1.23405e-27)
+ self.assertEqual("1.234e+132", "%.3e" %1.23405e+132)
+ self.assertEqual("1.234e-132", "%.3e" %1.23405e-132)
+ self.assertEqual("1.234E+132", "%.3E" %1.23405e+132)
+ self.assertEqual("1.234E-132", "%.3E" %1.23405e-132)
+
+
def test_main():
test_support.run_unittest(
FormatFunctionsTestCase,
UnknownFormatTestCase,
IEEEFormatTestCase,
- #ReprTestCase
+ #ReprTestCase,
+ StrFormatETestCase,
)
if __name__ == '__main__':
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com