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
22b85b3e
Kaydet (Commit)
22b85b3e
authored
Tem 17, 2008
tarafından
Eric Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Backed out r65073, pending fixing it in Windows.
üst
a4fac36e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
18 additions
and
44 deletions
+18
-44
stdtypes.rst
Doc/library/stdtypes.rst
+2
-2
string.rst
Doc/library/string.rst
+3
-4
test_format.py
Lib/test/test_format.py
+0
-11
test_types.py
Lib/test/test_types.py
+2
-10
NEWS
Misc/NEWS
+0
-3
formatter.h
Objects/stringlib/formatter.h
+6
-6
unicodeobject.c
Objects/unicodeobject.c
+5
-8
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
22b85b3e
...
...
@@ -1223,9 +1223,9 @@ The conversion types are:
+------------+-----------------------------------------------------+-------+
| ``'E'`` | Floating point exponential format (uppercase). | \(3) |
+------------+-----------------------------------------------------+-------+
| ``'f'`` | Floating point decimal format
(lowercase).
| \(3) |
| ``'f'`` | Floating point decimal format
.
| \(3) |
+------------+-----------------------------------------------------+-------+
| ``'F'`` | Floating point decimal format
(uppercase).
| \(3) |
| ``'F'`` | Floating point decimal format
.
| \(3) |
+------------+-----------------------------------------------------+-------+
| ``'g'`` | Floating point format. Uses lowercase exponential | \(4) |
| | format if exponent is less than -4 or not less than | |
...
...
Doc/library/string.rst
Dosyayı görüntüle @
22b85b3e
...
...
@@ -402,14 +402,13 @@ The available presentation types for floating point and decimal values are:
| ``'e'`` | Exponent notation. Prints the number in scientific |
| | notation using the letter 'e' to indicate the exponent. |
+---------+----------------------------------------------------------+
| ``'E'`` | Exponent notation. Same as ``'e'`` except it
converts
|
| |
the number to upper case.
|
| ``'E'`` | Exponent notation. Same as ``'e'`` except it
uses an
|
| |
upper case 'E' as the separator character.
|
+---------+----------------------------------------------------------+
| ``'f'`` | Fixed point. Displays the number as a fixed-point |
| | number. |
+---------+----------------------------------------------------------+
| ``'F'`` | Fixed point. Same as ``'f'`` except it converts the |
| | number to upper case. |
| ``'F'`` | Fixed point. Same as ``'f'``. |
+---------+----------------------------------------------------------+
| ``'g'`` | General format. This prints the number as a fixed-point |
| | number, unless the number is too large, in which case |
...
...
Lib/test/test_format.py
Dosyayı görüntüle @
22b85b3e
...
...
@@ -79,17 +79,6 @@ class FormatTest(unittest.TestCase):
testformat
(
"
%#.*
f"
,
(
110
,
-
1.e+100
/
3.
))
testformat
(
"
%#.*
F"
,
(
110
,
-
1.e+100
/
3.
))
overflowrequired
=
0
# check for %f and %F
testformat
(
"
%
f"
,
(
1.0
,),
"1.000000"
)
testformat
(
"
%
F"
,
(
1.0
,),
"1.000000"
)
testformat
(
"
%
f"
,
(
1e100
,),
"1e+100"
)
testformat
(
"
%
F"
,
(
1e100
,),
"1E+100"
)
testformat
(
"
%
f"
,
(
1e100
,),
"1e+100"
)
testformat
(
"
%
F"
,
(
1e100
,),
"1E+100"
)
testformat
(
"
%
f"
,
(
float
(
'nan'
),),
"nan"
)
testformat
(
"
%
F"
,
(
float
(
'nan'
),),
"NAN"
)
testformat
(
"
%
f"
,
(
float
(
'inf'
),),
"inf"
)
testformat
(
"
%
F"
,
(
float
(
'inf'
),),
"INF"
)
# Formatting of integers. Overflow is not ok
overflowok
=
0
testformat
(
"
%
x"
,
10
,
"a"
)
...
...
Lib/test/test_types.py
Dosyayı görüntüle @
22b85b3e
...
...
@@ -514,17 +514,9 @@ class TypesTests(unittest.TestCase):
test
(
1.0
,
'+f'
,
'+1.000000'
)
test
(
-
1.0
,
'+f'
,
'-1.000000'
)
test
(
1.1234e90
,
'f'
,
'1.1234e+90'
)
test
(
1.1234e90
,
'F'
,
'1.1234
E
+90'
)
test
(
1.1234e90
,
'F'
,
'1.1234
e
+90'
)
test
(
1.1234e200
,
'f'
,
'1.1234e+200'
)
test
(
1.1234e200
,
'F'
,
'1.1234E+200'
)
test
(
1e100
,
'x<20f'
,
'1e+100xxxxxxxxxxxxxx'
)
test
(
1e100
,
'x<20F'
,
'1E+100xxxxxxxxxxxxxx'
)
test
(
float
(
'nan'
),
'f'
,
'nan'
)
test
(
float
(
'nan'
),
'F'
,
'NAN'
)
test
(
float
(
'inf'
),
'f'
,
'inf'
)
test
(
float
(
'inf'
),
'F'
,
'INF'
)
test
(
float
(
'-inf'
),
'f'
,
'-inf'
)
test
(
float
(
'-inf'
),
'F'
,
'-INF'
)
test
(
1.1234e200
,
'F'
,
'1.1234e+200'
)
test
(
1.0
,
'e'
,
'1.000000e+00'
)
test
(
-
1.0
,
'e'
,
'-1.000000e+00'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
22b85b3e
...
...
@@ -12,9 +12,6 @@ What's new in Python 3.0b2?
Core and Builtins
-----------------
- Issue #3382: Make '%F' and float.__format__('F') convert results
to uppercase.
- Issue #3008: the float type has a new instance method 'float.hex'
and a new class method 'float.fromhex' to convert floating-point
numbers to and from hexadecimal strings, respectively.
...
...
Objects/stringlib/formatter.h
Dosyayı görüntüle @
22b85b3e
...
...
@@ -741,6 +741,10 @@ format_float_internal(PyObject *value,
/* first, do the conversion as 8-bit chars, using the platform's
snprintf. then, if needed, convert to unicode. */
/* 'F' is the same as 'f', per the PEP */
if
(
type
==
'F'
)
type
=
'f'
;
x
=
PyFloat_AsDouble
(
value
);
if
(
x
==
-
1
.
0
&&
PyErr_Occurred
())
...
...
@@ -754,12 +758,8 @@ format_float_internal(PyObject *value,
if
(
precision
<
0
)
precision
=
6
;
if
((
type
==
'f'
||
type
==
'F'
)
&&
(
fabs
(
x
)
/
1e25
)
>=
1e25
)
{
if
(
type
==
'f'
)
type
=
'g'
;
else
type
=
'G'
;
}
if
(
type
==
'f'
&&
(
fabs
(
x
)
/
1e25
)
>=
1e25
)
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 @
22b85b3e
...
...
@@ -8588,12 +8588,8 @@ formatfloat(Py_UNICODE *buf,
return
-
1
;
if
(
prec
<
0
)
prec
=
6
;
if
((
type
==
'f'
||
type
==
'F'
)
&&
(
fabs
(
x
)
/
1e25
)
>=
1e25
)
{
if
(
type
==
'f'
)
type
=
'g'
;
else
type
=
'G'
;
}
if
(
type
==
'f'
&&
(
fabs
(
x
)
/
1e25
)
>=
1e25
)
type
=
'g'
;
/* Worst case length calc to ensure no buffer overrun:
'g' formats:
...
...
@@ -8612,8 +8608,7 @@ formatfloat(Py_UNICODE *buf,
*/
if
(((
type
==
'g'
||
type
==
'G'
)
&&
buflen
<=
(
size_t
)
10
+
(
size_t
)
prec
)
||
((
type
==
'f'
||
type
==
'F'
)
&&
buflen
<=
(
size_t
)
53
+
(
size_t
)
prec
))
{
(
type
==
'f'
&&
buflen
<=
(
size_t
)
53
+
(
size_t
)
prec
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"formatted float is too long (precision too large?)"
);
return
-
1
;
...
...
@@ -9096,6 +9091,8 @@ PyObject *PyUnicode_Format(PyObject *format,
case
'F'
:
case
'g'
:
case
'G'
:
if
(
c
==
'F'
)
c
=
'f'
;
pbuf
=
formatbuf
;
len
=
formatfloat
(
pbuf
,
sizeof
(
formatbuf
)
/
sizeof
(
Py_UNICODE
),
flags
,
prec
,
c
,
v
);
...
...
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