Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (revision 76582) +++ Objects/unicodeobject.c (working copy) @@ -8809,8 +8809,6 @@ case 'F': case 'g': case 'G': - if (c == 'F') - c = 'f'; temp = formatfloat(v, flags, prec, c); if (temp == NULL) goto onError; Index: Objects/stringobject.c =================================================================== --- Objects/stringobject.c (revision 76582) +++ Objects/stringobject.c (working copy) @@ -4966,8 +4966,6 @@ case 'F': case 'g': case 'G': - if (c == 'F') - c = 'f'; temp = formatfloat(v, flags, prec, c); if (temp == NULL) goto error; Index: Lib/test/formatfloat_testcases.txt =================================================================== --- Lib/test/formatfloat_testcases.txt (revision 76582) +++ Lib/test/formatfloat_testcases.txt (working copy) @@ -81,6 +81,14 @@ %f 0.0000005001 -> 0.000001 %f 0.0000004999 -> 0.000000 +-- nans and infinities +%f nan -> nan +%f inf -> inf +%f -infinity -> -inf +%F nan -> NAN +%F infinity -> INF +%F -inf -> -INF + -- 'e' code formatting with explicit precision (>= 0). Output should -- always have exactly the number of places after the point that were -- requested. @@ -202,6 +210,14 @@ %#.1e 123.4 -> 1.2e+02 %#.2e 0.0001357 -> 1.36e-04 +-- nans and infinities +%e nan -> nan +%e inf -> inf +%e -infinity -> -inf +%E nan -> NAN +%E infinity -> INF +%E -inf -> -INF + -- 'g' code formatting. -- zeros @@ -314,6 +330,14 @@ %#.5g 234.56 -> 234.56 %#.6g 234.56 -> 234.560 +-- nans and infinities +%g nan -> nan +%g inf -> inf +%g -infinity -> -inf +%G nan -> NAN +%G infinity -> INF +%G -inf -> -INF + -- for repr formatting see the separate test_short_repr test in -- test_float.py. Not all platforms use short repr for floats. Index: Lib/test/test_float.py =================================================================== --- Lib/test/test_float.py (revision 76582) +++ Lib/test/test_float.py (working copy) @@ -321,8 +321,10 @@ lhs, rhs = map(str.strip, line.split('->')) fmt, arg = lhs.split() - self.assertEqual(fmt % float(arg), rhs) - self.assertEqual(fmt % -float(arg), '-' + rhs) + arg = float(arg) + self.assertEqual(fmt % arg, rhs) + if not math.isnan(arg) and copysign(1.0, arg) > 0.0: + self.assertEqual(fmt % -arg, '-' + rhs) def test_issue5864(self): self.assertEquals(format(123.456, '.4'), '123.5')