summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-11-24 14:27:02 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-11-24 14:27:02 (GMT)
commit6b87f117caba3a6af28f0d0afb05515ae8997620 (patch)
tree73b2396c2562f2c64355df5cad7a3771b5360bd8 /Doc/tutorial
parent9a03f2fd03278d2c12dfe253de1bbed7c0c9c506 (diff)
downloadcpython-6b87f117caba3a6af28f0d0afb05515ae8997620.zip
cpython-6b87f117caba3a6af28f0d0afb05515ae8997620.tar.gz
cpython-6b87f117caba3a6af28f0d0afb05515ae8997620.tar.bz2
Fix some documentation examples involving the repr of a float.
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/floatingpoint.rst2
-rw-r--r--Doc/tutorial/inputoutput.rst8
-rw-r--r--Doc/tutorial/stdlib2.rst9
3 files changed, 11 insertions, 8 deletions
diff --git a/Doc/tutorial/floatingpoint.rst b/Doc/tutorial/floatingpoint.rst
index 29c7a66..3554e4f 100644
--- a/Doc/tutorial/floatingpoint.rst
+++ b/Doc/tutorial/floatingpoint.rst
@@ -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.99999999999999989
+ 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"
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst
index 0259749..8d23cc1 100644
--- a/Doc/tutorial/inputoutput.rst
+++ b/Doc/tutorial/inputoutput.rst
@@ -49,10 +49,10 @@ Some examples::
'Hello, world.'
>>> repr(s)
"'Hello, world.'"
- >>> str(0.1)
- '0.1'
- >>> repr(0.1)
- '0.10000000000000001'
+ >>> str(1.0/7.0)
+ '0.142857142857'
+ >>> repr(1.0/7.0)
+ '0.14285714285714285'
>>> x = 10 * 3.25
>>> y = 200 * 200
>>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'
diff --git a/Doc/tutorial/stdlib2.rst b/Doc/tutorial/stdlib2.rst
index 0197a6f..4ae85b1 100644
--- a/Doc/tutorial/stdlib2.rst
+++ b/Doc/tutorial/stdlib2.rst
@@ -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