Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
33841c34
Kaydet (Commit)
33841c34
authored
May 01, 2009
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #5859: Remove '%f' to '%g' formatting switch for large floats.
üst
f489caf5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
19 deletions
+27
-19
stdtypes.rst
Doc/library/stdtypes.rst
+3
-7
formatfloat_testcases.txt
Lib/test/formatfloat_testcases.txt
+1
-1
test_types.py
Lib/test/test_types.py
+19
-4
NEWS
Misc/NEWS
+4
-2
formatter.h
Objects/stringlib/formatter.h
+0
-2
unicodeobject.c
Objects/unicodeobject.c
+0
-3
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
33841c34
...
...
@@ -1321,9 +1321,9 @@ that ``'\0'`` is the end of the string.
.. XXX Examples?
For safety reasons, floating point precisions are clipped to 50; ``%f``
conversions for numbers whose absolute value is over 1e50 are replaced by ``%g``
conversions. [#]_ All other errors raise except
ions.
.. versionchanged:: 3.1
``%f`` conversions for numbers whose absolute value is over 1e50 are no
longer replaced by ``%g`` convers
ions.
.. index::
module: string
...
...
@@ -2723,10 +2723,6 @@ The following attributes are only supported by :term:`new-style class`\ es.
.. [#] To format only a tuple you should therefore provide a singleton tuple whose only
element is the tuple to be formatted.
.. [#] These numbers are fairly arbitrary. They are intended to avoid printing endless
strings of meaningless digits without hampering correct use and without having
to know the exact precision of floating point values on a particular machine.
.. [#] The advantage of leaving the newline on is that returning an empty string is
then an unambiguous EOF indication. It is also possible (in cases where it
might matter, for example, if you want to make an exact copy of a file while
...
...
Lib/test/formatfloat_testcases.txt
Dosyayı görüntüle @
33841c34
...
...
@@ -22,8 +22,8 @@
%.0f 123.456 -> 123
%.0f 1234.56 -> 1235
%.0f 1e49 -> 9999999999999999464902769475481793196872414789632
-- %.0f 1e50 -> 100000000000000007629769841091887003294964970946560
%.0f 9.9999999999999987e+49 -> 99999999999999986860582406952576489172979654066176
%.0f 1e50 -> 100000000000000007629769841091887003294964970946560
-- precision 1
%.1f 0.0001 -> 0.0
...
...
Lib/test/test_types.py
Dosyayı görüntüle @
33841c34
...
...
@@ -538,10 +538,25 @@ class TypesTests(unittest.TestCase):
test
(
-
1.0
,
' f'
,
'-1.000000'
)
test
(
1.0
,
'+f'
,
'+1.000000'
)
test
(
-
1.0
,
'+f'
,
'-1.000000'
)
test
(
1.1234e90
,
'f'
,
'1.1234e+90'
)
test
(
1.1234e90
,
'F'
,
'1.1234e+90'
)
test
(
1.1234e200
,
'f'
,
'1.1234e+200'
)
test
(
1.1234e200
,
'F'
,
'1.1234e+200'
)
# Python versions <= 3.0 switched from 'f' to 'g' formatting for
# values larger than 1e50. No longer.
f
=
1.1234e90
for
fmt
in
'f'
,
'F'
:
# don't do a direct equality check, since on some
# platforms only the first few digits of dtoa
# will be reliable
result
=
f
.
__format__
(
fmt
)
self
.
assertEqual
(
len
(
result
),
98
)
self
.
assertEqual
(
result
[
-
7
],
'.'
)
self
.
assert_
(
result
[:
12
]
in
(
'112340000000'
,
'112339999999'
))
f
=
1.1234e200
for
fmt
in
'f'
,
'F'
:
result
=
f
.
__format__
(
fmt
)
self
.
assertEqual
(
len
(
result
),
208
)
self
.
assertEqual
(
result
[
-
7
],
'.'
)
self
.
assert_
(
result
[:
12
]
in
(
'112340000000'
,
'112339999999'
))
test
(
1.0
,
'e'
,
'1.000000e+00'
)
test
(
-
1.0
,
'e'
,
'-1.000000e+00'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
33841c34
...
...
@@ -12,8 +12,10 @@ What's New in Python 3.1 beta 1?
Core and Builtins
-----------------
- Issue #5859: Remove length restrictions for float formatting:
'%.67f' % 12.34 and '%.120e' % 12.34 no longer raise an exception.
- Issue #5859: Remove switch from '%f' to '%g'-style formatting for
floats with absolute value over 1e50. Also remove length
restrictions for float formatting: '%.67f' % 12.34 and '%.120e' %
12.34 no longer raise an exception.
- Issue #1588: Add complex.__format__. For example,
format(complex(1, 2./3), '.5') now produces a sensible result.
...
...
Objects/stringlib/formatter.h
Dosyayı görüntüle @
33841c34
...
...
@@ -934,8 +934,6 @@ format_float_internal(PyObject *value,
if
(
precision
<
0
)
precision
=
6
;
if
((
type
==
'f'
||
type
==
'F'
)
&&
fabs
(
val
)
>=
1e50
)
type
=
'g'
;
/* Cast "type", because if we're in unicode we need to pass a
8-bit char. This is safe, because we've restricted what "type"
...
...
Objects/unicodeobject.c
Dosyayı görüntüle @
33841c34
...
...
@@ -8808,9 +8808,6 @@ formatfloat(PyObject *v, int flags, int prec, int type)
if
(
prec
<
0
)
prec
=
6
;
if
(
type
==
'f'
&&
fabs
(
x
)
>=
1e50
)
type
=
'g'
;
p
=
PyOS_double_to_string
(
x
,
type
,
prec
,
(
flags
&
F_ALT
)
?
Py_DTSF_ALT
:
0
,
NULL
);
if
(
p
==
NULL
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment