@@ -40,23 +40,23 @@ decimal floating point arithmetic. It offers several advantages over the
40
40
people learn at school." -- excerpt from the decimal arithmetic specification.
41
41
42
42
* Decimal numbers can be represented exactly. In contrast, numbers like
43
- :const: ` ! 1.1 ` and :const: ` ! 2.2 ` do not have exact representations in binary
43
+ `` 1.1 `` and `` 2.2 ` ` do not have exact representations in binary
44
44
floating point. End users typically would not expect ``1.1 + 2.2 `` to display
45
- as :const: ` ! 3.3000000000000003 ` as it does with binary floating point.
45
+ as `` 3.3000000000000003 ` ` as it does with binary floating point.
46
46
47
47
* The exactness carries over into arithmetic. In decimal floating point, ``0.1
48
48
+ 0.1 + 0.1 - 0.3 `` is exactly equal to zero. In binary floating point, the result
49
- is :const: ` ! 5.5511151231257827e-017 `. While near to zero, the differences
49
+ is `` 5.5511151231257827e-017 ` `. While near to zero, the differences
50
50
prevent reliable equality testing and differences can accumulate. For this
51
51
reason, decimal is preferred in accounting applications which have strict
52
52
equality invariants.
53
53
54
54
* The decimal module incorporates a notion of significant places so that ``1.30
55
- + 1.20 `` is :const: ` ! 2.50 `. The trailing zero is kept to indicate significance.
55
+ + 1.20 `` is `` 2.50 ` `. The trailing zero is kept to indicate significance.
56
56
This is the customary presentation for monetary applications. For
57
57
multiplication, the "schoolbook" approach uses all the figures in the
58
- multiplicands. For instance, ``1.3 * 1.2 `` gives :const: ` ! 1.56 ` while ``1.30 *
59
- 1.20 `` gives :const: ` ! 1.5600 `.
58
+ multiplicands. For instance, ``1.3 * 1.2 `` gives `` 1.56 ` ` while ``1.30 *
59
+ 1.20 `` gives `` 1.5600 ` `.
60
60
61
61
* Unlike hardware based binary floating point, the decimal module has a user
62
62
alterable precision (defaulting to 28 places) which can be as large as needed for
@@ -88,8 +88,8 @@ context for arithmetic, and signals.
88
88
A decimal number is immutable. It has a sign, coefficient digits, and an
89
89
exponent. To preserve significance, the coefficient digits do not truncate
90
90
trailing zeros. Decimals also include special values such as
91
- :const: ` ! Infinity `, :const: ` ! -Infinity `, and :const: ` ! NaN `. The standard also
92
- differentiates :const: ` ! -0 ` from :const: ` !+0 `.
91
+ `` Infinity ``, `` -Infinity `` , and `` NaN ` `. The standard also
92
+ differentiates `` -0 `` from `` +0 ` `.
93
93
94
94
The context for arithmetic is an environment specifying precision, rounding
95
95
rules, limits on exponents, flags indicating the results of operations, and trap
@@ -139,8 +139,8 @@ precision, rounding, or enabled traps::
139
139
Decimal instances can be constructed from integers, strings, floats, or tuples.
140
140
Construction from an integer or a float performs an exact conversion of the
141
141
value of that integer or float. Decimal numbers include special values such as
142
- :const: ` ! NaN ` which stands for "Not a number", positive and negative
143
- :const: ` ! Infinity `, and :const: ` !-0 `::
142
+ `` NaN ` ` which stands for "Not a number", positive and negative
143
+ `` Infinity `` , and `` -0 ` `::
144
144
145
145
>>> getcontext().prec = 28
146
146
>>> Decimal(10)
@@ -309,7 +309,7 @@ using the :meth:`~Context.clear_flags` method. ::
309
309
Context(prec=9, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999,
310
310
capitals=1, clamp=0, flags=[Inexact, Rounded], traps=[])
311
311
312
- The *flags * entry shows that the rational approximation to :const: ` !Pi ` was
312
+ The *flags * entry shows that the rational approximation to `` Pi ` ` was
313
313
rounded (digits beyond the context precision were thrown away) and that the
314
314
result is inexact (some of the discarded digits were non-zero).
315
315
@@ -369,7 +369,7 @@ Decimal objects
369
369
with the fullwidth digits ``'\uff10' `` through ``'\uff19' ``.
370
370
371
371
If *value * is a :class: `tuple `, it should have three components, a sign
372
- (:const: ` !0 ` for positive or :const: ` !1 ` for negative), a :class: `tuple ` of
372
+ (`` 0 `` for positive or `` 1 ` ` for negative), a :class: `tuple ` of
373
373
digits, and an integer exponent. For example, ``Decimal((0, (1, 4, 1, 4), -3)) ``
374
374
returns ``Decimal('1.414') ``.
375
375
@@ -387,7 +387,7 @@ Decimal objects
387
387
The purpose of the *context * argument is determining what to do if *value * is a
388
388
malformed string. If the context traps :const: `InvalidOperation `, an exception
389
389
is raised; otherwise, the constructor returns a new Decimal with the value of
390
- :const: ` ! NaN `.
390
+ `` NaN ` `.
391
391
392
392
Once constructed, :class: `Decimal ` objects are immutable.
393
393
@@ -701,7 +701,7 @@ Decimal objects
701
701
.. method :: max(other, context=None)
702
702
703
703
Like ``max(self, other) `` except that the context rounding rule is applied
704
- before returning and that :const: ` ! NaN ` values are either signaled or
704
+ before returning and that `` NaN ` ` values are either signaled or
705
705
ignored (depending on the context and whether they are signaling or
706
706
quiet).
707
707
@@ -713,7 +713,7 @@ Decimal objects
713
713
.. method :: min(other, context=None)
714
714
715
715
Like ``min(self, other) `` except that the context rounding rule is applied
716
- before returning and that :const: ` ! NaN ` values are either signaled or
716
+ before returning and that `` NaN ` ` values are either signaled or
717
717
ignored (depending on the context and whether they are signaling or
718
718
quiet).
719
719
@@ -830,7 +830,7 @@ Decimal objects
830
830
.. method :: same_quantum(other, context=None)
831
831
832
832
Test whether self and other have the same exponent or whether both are
833
- :const: ` ! NaN `.
833
+ `` NaN ` `.
834
834
835
835
This operation is unaffected by context and is quiet: no flags are changed
836
836
and no rounding is performed. As an exception, the C version may raise
@@ -896,7 +896,7 @@ The :meth:`~Decimal.logical_and`, :meth:`~Decimal.logical_invert`, :meth:`~Decim
896
896
and :meth: `~Decimal.logical_xor ` methods expect their arguments to be *logical
897
897
operands *. A *logical operand * is a :class: `Decimal ` instance whose
898
898
exponent and sign are both zero, and whose digits are all either
899
- :const: ` !0 ` or :const: ` !1 `.
899
+ `` 0 `` or `` 1 ` `.
900
900
901
901
.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
902
902
@@ -982,7 +982,7 @@ described below. In addition, the module provides three pre-made contexts:
982
982
exceptions are not raised during computations).
983
983
984
984
Because the traps are disabled, this context is useful for applications that
985
- prefer to have result value of :const: ` ! NaN ` or :const: ` ! Infinity ` instead of
985
+ prefer to have result value of `` NaN `` or `` Infinity ` ` instead of
986
986
raising exceptions. This allows an application to complete a run in the
987
987
presence of conditions that would otherwise halt the program.
988
988
@@ -1016,7 +1016,7 @@ In addition to the three supplied contexts, new contexts can be created with the
1016
1016
default values are copied from the :const: `DefaultContext `. If the *flags *
1017
1017
field is not specified or is :const: `None `, all flags are cleared.
1018
1018
1019
- *prec * is an integer in the range [:const: ` !1 `, :const: `MAX_PREC `] that sets
1019
+ *prec * is an integer in the range [`` 1 ` `, :const: `MAX_PREC `] that sets
1020
1020
the precision for arithmetic operations in the context.
1021
1021
1022
1022
The *rounding * option is one of the constants listed in the section
@@ -1026,20 +1026,20 @@ In addition to the three supplied contexts, new contexts can be created with the
1026
1026
contexts should only set traps and leave the flags clear.
1027
1027
1028
1028
The *Emin * and *Emax * fields are integers specifying the outer limits allowable
1029
- for exponents. *Emin * must be in the range [:const: `MIN_EMIN `, :const: ` !0 `],
1030
- *Emax * in the range [:const: ` !0 `, :const: `MAX_EMAX `].
1029
+ for exponents. *Emin * must be in the range [:const: `MIN_EMIN `, `` 0 ` `],
1030
+ *Emax * in the range [`` 0 ` `, :const: `MAX_EMAX `].
1031
1031
1032
- The *capitals * field is either :const: ` !0 ` or :const: ` !1 ` (the default). If set to
1033
- :const: ` !1 ` , exponents are printed with a capital :const: ` !E `; otherwise, a
1034
- lowercase :const: ` !e ` is used: :const: ` ! Decimal('6.02e+23') `.
1032
+ The *capitals * field is either `` 0 `` or `` 1 ` ` (the default). If set to
1033
+ `` 1 `` , exponents are printed with a capital `` E ` `; otherwise, a
1034
+ lowercase `` e `` is used: `` Decimal('6.02e+23') ` `.
1035
1035
1036
- The *clamp * field is either :const: ` !0 ` (the default) or :const: ` !1 `.
1037
- If set to :const: ` !1 `, the exponent ``e `` of a :class: `Decimal `
1036
+ The *clamp * field is either `` 0 `` (the default) or `` 1 ` `.
1037
+ If set to `` 1 ` `, the exponent ``e `` of a :class: `Decimal `
1038
1038
instance representable in this context is strictly limited to the
1039
1039
range ``Emin - prec + 1 <= e <= Emax - prec + 1 ``. If *clamp * is
1040
- :const: ` !0 ` then a weaker condition holds: the adjusted exponent of
1040
+ `` 0 ` ` then a weaker condition holds: the adjusted exponent of
1041
1041
the :class: `Decimal ` instance is at most ``Emax ``. When *clamp * is
1042
- :const: ` !1 `, a large normal number will, where possible, have its
1042
+ `` 1 ` `, a large normal number will, where possible, have its
1043
1043
exponent reduced and a corresponding number of zeros added to its
1044
1044
coefficient, in order to fit the exponent constraints; this
1045
1045
preserves the value of the number but loses information about
@@ -1048,7 +1048,7 @@ In addition to the three supplied contexts, new contexts can be created with the
1048
1048
>>> Context(prec=6, Emax=999, clamp=1).create_decimal('1.23e999')
1049
1049
Decimal('1.23000E+999')
1050
1050
1051
- A *clamp * value of :const: ` !1 ` allows compatibility with the
1051
+ A *clamp * value of `` 1 ` ` allows compatibility with the
1052
1052
fixed-width decimal interchange formats specified in IEEE 754.
1053
1053
1054
1054
The :class: `Context ` class defines several general purpose methods as well as
@@ -1064,11 +1064,11 @@ In addition to the three supplied contexts, new contexts can be created with the
1064
1064
1065
1065
.. method :: clear_flags()
1066
1066
1067
- Resets all of the flags to :const: ` !0 `.
1067
+ Resets all of the flags to `` 0 ` `.
1068
1068
1069
1069
.. method :: clear_traps()
1070
1070
1071
- Resets all of the traps to :const: ` !0 `.
1071
+ Resets all of the traps to `` 0 ` `.
1072
1072
1073
1073
.. versionadded :: 3.3
1074
1074
@@ -1480,17 +1480,17 @@ Constants
1480
1480
The constants in this section are only relevant for the C module. They
1481
1481
are also included in the pure Python version for compatibility.
1482
1482
1483
- +---------------------+----------------------+- -------------------------------+
1484
- | | 32-bit | 64-bit |
1485
- +=====================+======================+= ===============================+
1486
- | .. data:: MAX_PREC | :const: ` ! 425000000 ` | :const: ` ! 999999999999999999 ` |
1487
- +---------------------+----------------------+- -------------------------------+
1488
- | .. data:: MAX_EMAX | :const: ` ! 425000000 ` | :const: ` ! 999999999999999999 ` |
1489
- +---------------------+----------------------+- -------------------------------+
1490
- | .. data:: MIN_EMIN | :const: ` ! -425000000 ` | :const: ` ! -999999999999999999 ` |
1491
- +---------------------+----------------------+- -------------------------------+
1492
- | .. data:: MIN_ETINY | :const: ` ! -849999999 ` | :const: ` ! -1999999999999999997 ` |
1493
- +---------------------+----------------------+- -------------------------------+
1483
+ +---------------------+---------------------+ -------------------------------+
1484
+ | | 32-bit | 64-bit |
1485
+ +=====================+=====================+ ===============================+
1486
+ | .. data:: MAX_PREC | `` 425000000 `` | `` 999999999999999999 `` |
1487
+ +---------------------+---------------------+ -------------------------------+
1488
+ | .. data:: MAX_EMAX | `` 425000000 `` | `` 999999999999999999 `` |
1489
+ +---------------------+---------------------+ -------------------------------+
1490
+ | .. data:: MIN_EMIN | `` -425000000 `` | `` -999999999999999999 `` |
1491
+ +---------------------+---------------------+ -------------------------------+
1492
+ | .. data:: MIN_ETINY | `` -849999999 `` | `` -1999999999999999997 `` |
1493
+ +---------------------+---------------------+ -------------------------------+
1494
1494
1495
1495
1496
1496
.. data :: HAVE_THREADS
@@ -1514,15 +1514,15 @@ Rounding modes
1514
1514
1515
1515
.. data :: ROUND_CEILING
1516
1516
1517
- Round towards :const: ` ! Infinity `.
1517
+ Round towards `` Infinity ` `.
1518
1518
1519
1519
.. data :: ROUND_DOWN
1520
1520
1521
1521
Round towards zero.
1522
1522
1523
1523
.. data :: ROUND_FLOOR
1524
1524
1525
- Round towards :const: ` ! -Infinity `.
1525
+ Round towards `` -Infinity ` `.
1526
1526
1527
1527
.. data :: ROUND_HALF_DOWN
1528
1528
@@ -1584,8 +1584,8 @@ condition.
1584
1584
Signals the division of a non-infinite number by zero.
1585
1585
1586
1586
Can occur with division, modulo division, or when raising a number to a negative
1587
- power. If this signal is not trapped, returns :const: ` ! Infinity ` or
1588
- :const: ` ! -Infinity ` with the sign determined by the inputs to the calculation.
1587
+ power. If this signal is not trapped, returns `` Infinity ` ` or
1588
+ `` -Infinity ` ` with the sign determined by the inputs to the calculation.
1589
1589
1590
1590
1591
1591
.. class :: Inexact
@@ -1602,7 +1602,7 @@ condition.
1602
1602
An invalid operation was performed.
1603
1603
1604
1604
Indicates that an operation was requested that does not make sense. If not
1605
- trapped, returns :const: ` ! NaN `. Possible causes include::
1605
+ trapped, returns `` NaN ` `. Possible causes include::
1606
1606
1607
1607
Infinity - Infinity
1608
1608
0 * Infinity
@@ -1622,7 +1622,7 @@ condition.
1622
1622
Indicates the exponent is larger than :attr: `!Emax ` after rounding has
1623
1623
occurred. If not trapped, the result depends on the rounding mode, either
1624
1624
pulling inward to the largest representable finite number or rounding outward
1625
- to :const: ` ! Infinity `. In either case, :class: `Inexact ` and :class: `Rounded `
1625
+ to `` Infinity ` `. In either case, :class: `Inexact ` and :class: `Rounded `
1626
1626
are also signaled.
1627
1627
1628
1628
@@ -1631,7 +1631,7 @@ condition.
1631
1631
Rounding occurred though possibly no information was lost.
1632
1632
1633
1633
Signaled whenever rounding discards digits; even if those digits are zero
1634
- (such as rounding :const: ` ! 5.00 ` to :const: ` ! 5.0 `). If not trapped, returns
1634
+ (such as rounding `` 5.00 `` to `` 5.0 ` `). If not trapped, returns
1635
1635
the result unchanged. This signal is used to detect loss of significant
1636
1636
digits.
1637
1637
@@ -1696,7 +1696,7 @@ Mitigating round-off error with increased precision
1696
1696
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1697
1697
1698
1698
The use of decimal floating point eliminates decimal representation error
1699
- (making it possible to represent :const: ` ! 0.1 ` exactly); however, some operations
1699
+ (making it possible to represent `` 0.1 ` ` exactly); however, some operations
1700
1700
can still incur round-off error when non-zero digits exceed the fixed precision.
1701
1701
1702
1702
The effects of round-off error can be amplified by the addition or subtraction
@@ -1746,8 +1746,8 @@ Special values
1746
1746
^^^^^^^^^^^^^^
1747
1747
1748
1748
The number system for the :mod: `decimal ` module provides special values
1749
- including :const: ` ! NaN `, :const: ` ! sNaN `, :const: ` ! -Infinity `, :const: ` ! Infinity `,
1750
- and two zeros, :const: ` ! +0 ` and :const: ` !-0 `.
1749
+ including `` NaN ``, `` sNaN ``, `` -Infinity ``, `` Infinity ` `,
1750
+ and two zeros, `` +0 `` and `` -0 ` `.
1751
1751
1752
1752
Infinities can be constructed directly with: ``Decimal('Infinity') ``. Also,
1753
1753
they can arise from dividing by zero when the :exc: `DivisionByZero ` signal is
@@ -1758,28 +1758,28 @@ The infinities are signed (affine) and can be used in arithmetic operations
1758
1758
where they get treated as very large, indeterminate numbers. For instance,
1759
1759
adding a constant to infinity gives another infinite result.
1760
1760
1761
- Some operations are indeterminate and return :const: ` ! NaN `, or if the
1761
+ Some operations are indeterminate and return `` NaN ` `, or if the
1762
1762
:exc: `InvalidOperation ` signal is trapped, raise an exception. For example,
1763
- ``0/0 `` returns :const: ` ! NaN ` which means "not a number". This variety of
1764
- :const: ` ! NaN ` is quiet and, once created, will flow through other computations
1765
- always resulting in another :const: ` ! NaN `. This behavior can be useful for a
1763
+ ``0/0 `` returns `` NaN ` ` which means "not a number". This variety of
1764
+ `` NaN ` ` is quiet and, once created, will flow through other computations
1765
+ always resulting in another `` NaN ` `. This behavior can be useful for a
1766
1766
series of computations that occasionally have missing inputs --- it allows the
1767
1767
calculation to proceed while flagging specific results as invalid.
1768
1768
1769
- A variant is :const: ` ! sNaN ` which signals rather than remaining quiet after every
1769
+ A variant is `` sNaN ` ` which signals rather than remaining quiet after every
1770
1770
operation. This is a useful return value when an invalid result needs to
1771
1771
interrupt a calculation for special handling.
1772
1772
1773
1773
The behavior of Python's comparison operators can be a little surprising where a
1774
- :const: ` ! NaN ` is involved. A test for equality where one of the operands is a
1775
- quiet or signaling :const: ` ! NaN ` always returns :const: `False ` (even when doing
1774
+ `` NaN ` ` is involved. A test for equality where one of the operands is a
1775
+ quiet or signaling `` NaN ` ` always returns :const: `False ` (even when doing
1776
1776
``Decimal('NaN')==Decimal('NaN') ``), while a test for inequality always returns
1777
1777
:const: `True `. An attempt to compare two Decimals using any of the ``< ``,
1778
1778
``<= ``, ``> `` or ``>= `` operators will raise the :exc: `InvalidOperation ` signal
1779
- if either operand is a :const: ` ! NaN `, and return :const: `False ` if this signal is
1779
+ if either operand is a `` NaN ` `, and return :const: `False ` if this signal is
1780
1780
not trapped. Note that the General Decimal Arithmetic specification does not
1781
1781
specify the behavior of direct comparisons; these rules for comparisons
1782
- involving a :const: ` ! NaN ` were taken from the IEEE 854 standard (see Table 3 in
1782
+ involving a `` NaN ` ` were taken from the IEEE 854 standard (see Table 3 in
1783
1783
section 5.7). To ensure strict standards-compliance, use the :meth: `~Decimal.compare `
1784
1784
and :meth: `~Decimal.compare_signal ` methods instead.
1785
1785
@@ -2066,8 +2066,8 @@ to handle the :meth:`~Decimal.quantize` step:
2066
2066
>>> div(b, a)
2067
2067
Decimal('0.03')
2068
2068
2069
- Q. There are many ways to express the same value. The numbers :const: ` ! 200 `,
2070
- :const: ` ! 200.000 `, :const: ` ! 2E2 `, and :const: ` ! .02E+4 ` all have the same value at
2069
+ Q. There are many ways to express the same value. The numbers `` 200 ` `,
2070
+ `` 200.000 ``, `` 2E2 `` , and `` .02E+4 ` ` all have the same value at
2071
2071
various precisions. Is there a way to transform them to a single recognizable
2072
2072
canonical value?
2073
2073
@@ -2083,7 +2083,7 @@ to get a non-exponential representation?
2083
2083
2084
2084
A. For some values, exponential notation is the only way to express the number
2085
2085
of significant places in the coefficient. For example, expressing
2086
- :const: ` ! 5.0E+3 ` as :const: ` ! 5000 ` keeps the value constant but cannot show the
2086
+ `` 5.0E+3 `` as `` 5000 ` ` keeps the value constant but cannot show the
2087
2087
original's two-place significance.
2088
2088
2089
2089
If an application does not care about tracking significance, it is easy to
0 commit comments