Skip to content

Commit d941dea

Browse files
hugovkCAM-Gerlach
andauthored
Apply suggestions from code review
Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent e1608be commit d941dea

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

Doc/library/decimal.rst

+24-24
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ differentiates :const:`!-0` from :const:`!+0`.
9494
The context for arithmetic is an environment specifying precision, rounding
9595
rules, limits on exponents, flags indicating the results of operations, and trap
9696
enablers which determine whether signals are treated as exceptions. Rounding
97-
options include :const:`~decimal.ROUND_CEILING`, :const:`ROUND_DOWN`,
97+
options include :const:`ROUND_CEILING`, :const:`ROUND_DOWN`,
9898
:const:`ROUND_FLOOR`, :const:`ROUND_HALF_DOWN`, :const:`ROUND_HALF_EVEN`,
9999
:const:`ROUND_HALF_UP`, :const:`ROUND_UP`, and :const:`ROUND_05UP`.
100100

@@ -250,7 +250,7 @@ And some mathematical functions are also available to Decimal:
250250
>>> Decimal('10').log10()
251251
Decimal('1')
252252

253-
The :meth:`~decimal.Decimal.quantize` method rounds a number to a fixed exponent. This method is
253+
The :meth:`~Decimal.quantize` method rounds a number to a fixed exponent. This method is
254254
useful for monetary applications that often round results to a fixed number of
255255
places:
256256

@@ -299,7 +299,7 @@ enabled:
299299
Contexts also have signal flags for monitoring exceptional conditions
300300
encountered during computations. The flags remain set until explicitly cleared,
301301
so it is best to clear the flags before each set of monitored computations by
302-
using the :meth:`~decimal.Context.clear_flags` method. ::
302+
using the :meth:`~Context.clear_flags` method. ::
303303

304304
>>> setcontext(ExtendedContext)
305305
>>> getcontext().clear_flags()
@@ -313,8 +313,8 @@ The *flags* entry shows that the rational approximation to :const:`!Pi` was
313313
rounded (digits beyond the context precision were thrown away) and that the
314314
result is inexact (some of the discarded digits were non-zero).
315315

316-
Individual traps are set using the dictionary in the :attr:`!traps` field of a
317-
context:
316+
Individual traps are set using the dictionary in the :attr:`~Context.traps`
317+
attribute of a context:
318318

319319
.. doctest:: newcontext
320320

@@ -790,7 +790,7 @@ Decimal objects
790790
the current thread's context is used.
791791

792792
An error is returned whenever the resulting exponent is greater than
793-
:attr:`!Emax` or less than :attr:`!Etiny`.
793+
:attr:`Emax` or less than :meth:`Etiny`.
794794

795795
.. method:: radix()
796796

@@ -892,8 +892,8 @@ Decimal objects
892892
Logical operands
893893
^^^^^^^^^^^^^^^^
894894

895-
The :meth:`~decimal.Decimal.logical_and`, :meth:`~decimal.Decimal.logical_invert`, :meth:`~decimal.Decimal.logical_or`,
896-
and :meth:`~decimal.Decimal.logical_xor` methods expect their arguments to be *logical
895+
The :meth:`~Decimal.logical_and`, :meth:`~Decimal.logical_invert`, :meth:`~Decimal.logical_or`,
896+
and :meth:`~Decimal.logical_xor` methods expect their arguments to be *logical
897897
operands*. A *logical operand* is a :class:`Decimal` instance whose
898898
exponent and sign are both zero, and whose digits are all either
899899
:const:`!0` or :const:`!1`.
@@ -1001,8 +1001,8 @@ described below. In addition, the module provides three pre-made contexts:
10011001
In single threaded environments, it is preferable to not use this context at
10021002
all. Instead, simply create contexts explicitly as described below.
10031003

1004-
The default values are :attr:`!prec`\ =\ :const:`!28`,
1005-
:attr:`!rounding`\ =\ :const:`ROUND_HALF_EVEN`,
1004+
The default values are :attr:`Context.prec`\ =\ ``28``,
1005+
:attr:`Context.rounding`\ =\ :const:`ROUND_HALF_EVEN`,
10061006
and enabled traps for :class:`Overflow`, :class:`InvalidOperation`, and
10071007
:class:`DivisionByZero`.
10081008

@@ -1054,7 +1054,7 @@ In addition to the three supplied contexts, new contexts can be created with the
10541054
The :class:`Context` class defines several general purpose methods as well as
10551055
a large number of methods for doing arithmetic directly in a given context.
10561056
In addition, for each of the :class:`Decimal` methods described above (with
1057-
the exception of the :meth:`~decimal.Decimal.adjusted` and :meth:`~decimal.Decimal.as_tuple` methods) there is
1057+
the exception of the :meth:`~Decimal.adjusted` and :meth:`~Decimal.as_tuple` methods) there is
10581058
a corresponding :class:`Context` method. For example, for a :class:`Context`
10591059
instance ``C`` and :class:`Decimal` instance ``x``, ``C.exp(x)`` is
10601060
equivalent to ``x.exp(context=C)``. Each :class:`Context` method accepts a
@@ -1570,7 +1570,7 @@ condition.
15701570
Altered an exponent to fit representation constraints.
15711571

15721572
Typically, clamping occurs when an exponent falls outside the context's
1573-
:attr:`!Emin` and :attr:`!Emax` limits. If possible, the exponent is reduced to
1573+
:attr:`~Context.Emin` and :attr:`~Context.Emax` limits. If possible, the exponent is reduced to
15741574
fit by adding zeros to the coefficient.
15751575

15761576

@@ -1638,7 +1638,7 @@ condition.
16381638

16391639
.. class:: Subnormal
16401640

1641-
Exponent was lower than :attr:`!Emin` prior to rounding.
1641+
Exponent was lower than :attr:`~Context.Emin` prior to rounding.
16421642

16431643
Occurs when an operation result is subnormal (the exponent is too small). If
16441644
not trapped, returns the result unchanged.
@@ -1780,8 +1780,8 @@ if either operand is a :const:`!NaN`, and return :const:`False` if this signal i
17801780
not trapped. Note that the General Decimal Arithmetic specification does not
17811781
specify the behavior of direct comparisons; these rules for comparisons
17821782
involving a :const:`!NaN` were taken from the IEEE 854 standard (see Table 3 in
1783-
section 5.7). To ensure strict standards-compliance, use the :meth:`~decimal.Decimal.compare`
1784-
and :meth:`~decimal.Decimal.compare_signal` methods instead.
1783+
section 5.7). To ensure strict standards-compliance, use the :meth:`~Decimal.compare`
1784+
and :meth:`~Decimal.compare_signal` methods instead.
17851785

17861786
The signed zeros can result from calculations that underflow. They keep the sign
17871787
that would have resulted if the calculation had been carried out to greater
@@ -2013,7 +2013,7 @@ Q. In a fixed-point application with two decimal places, some inputs have many
20132013
places and need to be rounded. Others are not supposed to have excess digits
20142014
and need to be validated. What methods should be used?
20152015

2016-
A. The :meth:`~decimal.Decimal.quantize` method rounds to a fixed number of decimal places. If
2016+
A. The :meth:`~Decimal.quantize` method rounds to a fixed number of decimal places. If
20172017
the :const:`Inexact` trap is set, it is also useful for validation:
20182018

20192019
>>> TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')
@@ -2037,7 +2037,7 @@ throughout an application?
20372037
A. Some operations like addition, subtraction, and multiplication by an integer
20382038
will automatically preserve fixed point. Others operations, like division and
20392039
non-integer multiplication, will change the number of decimal places and need to
2040-
be followed-up with a :meth:`~decimal.Decimal.quantize` step:
2040+
be followed-up with a :meth:`~Decimal.quantize` step:
20412041

20422042
>>> a = Decimal('102.72') # Initial fixed-point values
20432043
>>> b = Decimal('3.17')
@@ -2053,7 +2053,7 @@ be followed-up with a :meth:`~decimal.Decimal.quantize` step:
20532053
Decimal('0.03')
20542054

20552055
In developing fixed-point applications, it is convenient to define functions
2056-
to handle the :meth:`~decimal.Decimal.quantize` step:
2056+
to handle the :meth:`~Decimal.quantize` step:
20572057

20582058
>>> def mul(x, y, fp=TWOPLACES):
20592059
... return (x * y).quantize(fp)
@@ -2071,7 +2071,7 @@ Q. There are many ways to express the same value. The numbers :const:`!200`,
20712071
various precisions. Is there a way to transform them to a single recognizable
20722072
canonical value?
20732073

2074-
A. The :meth:`~decimal.Decimal.normalize` method maps all equivalent values to a single
2074+
A. The :meth:`~Decimal.normalize` method maps all equivalent values to a single
20752075
representative:
20762076

20772077
>>> values = map(Decimal, '200 200.000 2E2 .02E+4'.split())
@@ -2159,12 +2159,12 @@ for medium-sized numbers and the `Number Theoretic Transform
21592159
<https://en.wikipedia.org/wiki/Discrete_Fourier_transform_(general)#Number-theoretic_transform>`_
21602160
for very large numbers.
21612161

2162-
The context must be adapted for exact arbitrary precision arithmetic. :attr:`!Emin`
2163-
and :attr:`!Emax` should always be set to the maximum values, :attr:`!clamp`
2164-
should always be 0 (the default). Setting :attr:`!prec` requires some care.
2162+
The context must be adapted for exact arbitrary precision arithmetic. :attr:`~Context.Emin`
2163+
and :attr:`~Context.Emax` should always be set to the maximum values, :attr:`~Context.clamp`
2164+
should always be 0 (the default). Setting :attr:`~Context.prec` requires some care.
21652165

21662166
The easiest approach for trying out bignum arithmetic is to use the maximum
2167-
value for :attr:`!prec` as well [#]_::
2167+
value for :attr:`~Context.prec` as well [#]_::
21682168

21692169
>>> setcontext(Context(prec=MAX_PREC, Emax=MAX_EMAX, Emin=MIN_EMIN))
21702170
>>> x = Decimal(2) ** 256
@@ -2181,7 +2181,7 @@ the available memory will be insufficient::
21812181
MemoryError
21822182

21832183
On systems with overallocation (e.g. Linux), a more sophisticated approach is to
2184-
adjust :attr:`!prec` to the amount of available RAM. Suppose that you have 8GB of
2184+
adjust :attr:`~Context.prec` to the amount of available RAM. Suppose that you have 8GB of
21852185
RAM and expect 10 simultaneous operands using a maximum of 500MB each::
21862186

21872187
>>> import sys

0 commit comments

Comments
 (0)