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
6b87f117
Kaydet (Commit)
6b87f117
authored
Kas 24, 2009
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix some documentation examples involving the repr of a float.
üst
9a03f2fd
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
22 additions
and
19 deletions
+22
-19
design.rst
Doc/faq/design.rst
+3
-3
decimal.rst
Doc/library/decimal.rst
+4
-4
math.rst
Doc/library/math.rst
+1
-1
sqlite3.rst
Doc/library/sqlite3.rst
+2
-2
turtle.rst
Doc/library/turtle.rst
+1
-1
floatingpoint.rst
Doc/tutorial/floatingpoint.rst
+1
-1
inputoutput.rst
Doc/tutorial/inputoutput.rst
+4
-4
stdlib2.rst
Doc/tutorial/stdlib2.rst
+6
-3
No files found.
Doc/faq/design.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -75,9 +75,9 @@ necessary to make ``eval(repr(f)) == f`` true for any float f. The ``str()``
function prints fewer digits and this often results in the more sensible number
that was probably intended::
>>>
0.2
0.2000000000000000
1
>>> print
0.2
>>>
1.1 - 0.9
0.2000000000000000
7
>>> print
1.1 - 0.9
0.2
One of the consequences of this is that it is error-prone to compare the result
...
...
Doc/library/decimal.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -35,9 +35,9 @@ arithmetic. It offers several advantages over the :class:`float` datatype:
people learn at school." -- excerpt from the decimal arithmetic specification.
* Decimal numbers can be represented exactly. In contrast, numbers like
:const:`1.1`
do not have an exact representation in binary floating point. End
users typically would not expect :const:`1.1` to display as
:const:`1.1000000000000001
` as it does with binary floating point.
:const:`1.1`
and :const:`2.2` do not have an exact representations in binary
floating point. End users typically would not expect ``1.1 + 2.2`` to display
as :const:`3.3000000000000003
` as it does with binary floating point.
* The exactness carries over into arithmetic. In decimal floating point, ``0.1
+ 0.1 + 0.1 - 0.3`` is exactly equal to zero. In binary floating point, the result
...
...
@@ -193,7 +193,7 @@ floating point flying circus:
>>> str(a)
'1.34'
>>> float(a)
1.34
00000000000001
1.34
>>> round(a, 1) # round() first converts to binary floating point
1.3
>>> int(a)
...
...
Doc/library/math.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -90,7 +90,7 @@ Number-theoretic and representation functions
loss of precision by tracking multiple intermediate partial sums::
>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
0.999999999999999
8
9
0.9999999999999999
>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
1.0
...
...
Doc/library/sqlite3.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -83,7 +83,7 @@ This example uses the iterator form::
>>> for row in c:
... print row
...
(u'2006-01-05', u'BUY', u'RHAT', 100, 35.14
0000000000001
)
(u'2006-01-05', u'BUY', u'RHAT', 100, 35.14)
(u'2006-03-28', u'BUY', u'IBM', 1000, 45.0)
(u'2006-04-06', u'SELL', u'IBM', 500, 53.0)
(u'2006-04-05', u'BUY', u'MSOFT', 1000, 72.0)
...
...
@@ -601,7 +601,7 @@ Now we plug :class:`Row` in::
>>> type(r)
<type 'sqlite3.Row'>
>>> r
(u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.14
0000000000001
)
(u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.14)
>>> len(r)
5
>>> r[2]
...
...
Doc/library/turtle.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -875,7 +875,7 @@ Color control
>>> tup = (0.2, 0.8, 0.55)
>>> turtle.pencolor(tup)
>>> turtle.pencolor()
(0.2
0000000000000001, 0.80000000000000004
, 0.5490196078431373)
(0.2
, 0.8
, 0.5490196078431373)
>>> colormode(255)
>>> turtle.pencolor()
(51, 204, 140)
...
...
Doc/tutorial/floatingpoint.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -115,7 +115,7 @@ Another consequence is that since 0.1 is not exactly 1/10, summing ten values of
... sum += 0.1
...
>>> sum
0.999999999999999
8
9
0.9999999999999999
Binary floating-point arithmetic holds many surprises like this. The problem
with "0.1" is explained in precise detail below, in the "Representation Error"
...
...
Doc/tutorial/inputoutput.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -49,10 +49,10 @@ Some examples::
'Hello, world.'
>>> repr(s)
"'Hello, world.'"
>>> str(
0.1
)
'0.1'
>>> repr(
0.1
)
'0.1
0000000000000001
'
>>> str(
1.0/7.0
)
'0.1
42857142857
'
>>> repr(
1.0/7.0
)
'0.1
4285714285714285
'
>>> x = 10 * 3.25
>>> y = 200 * 200
>>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'
...
...
Doc/tutorial/stdlib2.rst
Dosyayı görüntüle @
6b87f117
...
...
@@ -362,10 +362,13 @@ results in decimal floating point and binary floating point. The difference
becomes significant if the results are rounded to the nearest cent::
>>> from decimal import *
>>> Decimal('0.70') * Decimal('1.05')
>>> x = Decimal('0.70') * Decimal('1.05')
>>> x
Decimal('0.7350')
>>> .70 * 1.05
0.73499999999999999
>>> x.quantize(Decimal('0.01')) # round to nearest cent
Decimal('0.74')
>>> round(.70 * 1.05, 2) # same calculation with floats
0.73
The :class:`Decimal` result keeps a trailing zero, automatically inferring four
place significance from multiplicands with two place significance. Decimal
...
...
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