summaryrefslogtreecommitdiffstats
path: root/Doc/lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-07-05 20:17:13 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-07-05 20:17:13 (GMT)
commitc4f93d4410163629e25e76431b8b7e6d5010771f (patch)
treed53175482e28151471e3fba812479c2083fa1ee5 /Doc/lib
parent9c719bafbffff4d0693fe0662f440f65a43ad71f (diff)
downloadcpython-c4f93d4410163629e25e76431b8b7e6d5010771f.zip
cpython-c4f93d4410163629e25e76431b8b7e6d5010771f.tar.gz
cpython-c4f93d4410163629e25e76431b8b7e6d5010771f.tar.bz2
Doc tested the recipes.
Diffstat (limited to 'Doc/lib')
-rw-r--r--Doc/lib/libdecimal.tex15
1 files changed, 10 insertions, 5 deletions
diff --git a/Doc/lib/libdecimal.tex b/Doc/lib/libdecimal.tex
index c0a2cc7..a996fc9 100644
--- a/Doc/lib/libdecimal.tex
+++ b/Doc/lib/libdecimal.tex
@@ -882,6 +882,7 @@ Here are some functions demonstrating ways to work with the
\begin{verbatim}
from decimal import Decimal, getcontext
+getcontext().prec = 28
def moneyfmt(value, places=2, curr='$', sep=',', dp='.', pos='', neg='-'):
"""Convert Decimal to a money formatted string.
@@ -928,7 +929,11 @@ def moneyfmt(value, places=2, curr='$', sep=',', dp='.', pos='', neg='-'):
return ''.join(result)
def pi():
- "Compute Pi to the current precision"
+ """Compute Pi to the current precision.
+
+ >>> print pi()
+ 3.141592653589793238462643383279502887
+ """
getcontext().prec += 9 # extra digits for intermediate steps
one = Decimal(1) # substitute "one=1.0" for regular floats
lastc, t, c, n, na, d, da = 0*one, 3*one, 3*one, 1, 0, 0, 24*one
@@ -951,7 +956,7 @@ def exp(x):
"""
getcontext().prec += 9 # extra digits for intermediate steps
one = Decimal(1) # substitute "one=1.0" for regular floats
- i, laste, e, fact, num = 0*one, 0*one, one, one, one
+ i, laste, e, fact, num = 0, 0, 1, 1, 1
while e != laste:
laste = e
i += 1
@@ -969,7 +974,7 @@ def cos(x):
"""
getcontext().prec += 9 # extra digits for intermediate steps
one = Decimal(1) # substitute "one=1.0" for regular floats
- i, laste, e, fact, num, sign = 0*one, 0*one, one, one, one, one
+ i, laste, e, fact, num, sign = 0, 0, 1, 1, 1, 1
while e != laste:
laste = e
i += 2
@@ -988,7 +993,7 @@ def sin(x):
"""
getcontext().prec += 9 # extra digits for intermediate steps
one = Decimal(1) # substitute "one=1.0" for regular floats
- i, laste, e, fact, num, sign = one, 0*one, x, one, x, one
+ i, laste, e, fact, num, sign = 1, 0, x, 1, x, 1
while e != laste:
laste = e
i += 2
@@ -997,6 +1002,6 @@ def sin(x):
sign *= -1
e += num / fact * sign
getcontext().prec -= 9
- return e
+ return e
\end{verbatim}