• Home
  • Raw
  • Download

Lines Matching +full:test +full:- +full:pypy3

1 :mod:`decimal` --- Decimal fixed point and floating point arithmetic
31 --------------
37 * Decimal "is based on a floating-point model which was designed with people
38 in mind, and necessarily has a paramount guiding principle -- computers must
40 people learn at school." -- excerpt from the decimal arithmetic specification.
48 + 0.1 + 0.1 - 0.3`` is exactly equal to zero. In binary floating point, the result
49 is ``5.5511151231257827e-017``. While near to zero, the differences
74 standards. While the built-in float type exposes only a modest portion of its
81 unrounded decimal arithmetic (sometimes called fixed-point arithmetic)
82 and rounded floating-point arithmetic." -- excerpt from the decimal
91 ``Infinity``, ``-Infinity``, and ``NaN``. The standard also
92 differentiates ``-0`` from ``+0``.
122 .. _decimal-tutorial:
124 Quick-start Tutorial
125 --------------------
133 Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999,
143 ``Infinity``, and ``-0``::
152 >>> Decimal((0, (3, 1, 4), -2))
160 >>> Decimal('-Infinity')
161 Decimal('-Infinity')
284 Context(prec=9, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999,
295 File "<pyshell#143>", line 1, in -toplevel-
309 Context(prec=9, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999,
314 result is inexact (some of the discarded digits were non-zero).
327 File "<pyshell#112>", line 1, in -toplevel-
340 .. _decimal-decimal:
343 ---------------
355 sign ::= '+' | '-'
359 decimal-part ::= digits '.' [digits] | ['.'] digits
360 exponent-part ::= indicator [sign] digits
363 numeric-value ::= decimal-part [exponent-part] | infinity
364 numeric-string ::= [sign] numeric-value | [sign] nan
368 alphabets (for example, Arabic-Indic and Devanāgarī digits) along
373 digits, and an integer exponent. For example, ``Decimal((0, (1, 4, 1, 4), -3))``
403 Underscores are allowed for grouping, as with integral and floating-point
406 Decimal floating point objects share many properties with the other built-in
418 >>> (-7) % 4
420 >>> Decimal(-7) % Decimal(4)
421 Decimal('-3')
427 >>> -7 // 4
428 -2
429 >>> Decimal(-7) // Decimal(4)
430 Decimal('-1')
433 ``divide-integer`` operations (respectively) as described in the
445 Mixed-type comparisons between :class:`Decimal` instances and other
465 >>> Decimal('-3.14').as_integer_ratio()
466 (-157, 50)
492 a < b ==> Decimal('-1')
511 Decimal('-1')
515 representation, ``Decimal('-1')`` if the first operand is lower in the
556 >>> Decimal('2.3').copy_sign(Decimal('-1.5'))
557 Decimal('-2.3')
582 ``0x1.999999999999ap-4``. That equivalent value in decimal is
596 >>> Decimal.from_float(float('-inf'))
597 Decimal('-Infinity')
603 Fused multiply-add. Return self*other+third with no rounding of the
674 ``Decimal('-Infinity')`` is returned and the :const:`DivisionByZero` flag
682 digit-wise ``and`` of the two operands.
687 result is the digit-wise inversion of the operand.
693 digit-wise ``or`` of the two operands.
699 digit-wise exclusive or of the two operands.
758 * ``"-Infinity"``, indicating that the operand is negative infinity.
759 * ``"-Normal"``, indicating that the operand is a negative normal number.
760 * ``"-Subnormal"``, indicating that the operand is negative and subnormal.
761 * ``"-Zero"``, indicating that the operand is a negative zero.
781 the right-hand operand.
806 ``self - n * other`` where ``n`` is the integer nearest to the exact
813 Decimal('-2')
817 Decimal('-5')
823 the range -precision through precision. The absolute value of the second
832 Test whether self and other have the same exponent or whether both are
849 the range -precision through precision. The absolute value of the second
904 .. _decimal-context:
907 ---------------
932 to a copy of *ctx* on entry to the with-statement and restore the previous context
933 when exiting the with-statement. If no context is specified, a copy of the
963 described below. In addition, the module provides three pre-made contexts:
996 This context is most useful in multi-threaded environments. Changing one of the
997 fields before threads are started has the effect of setting system-wide
1039 range ``Emin - prec + 1 <= e <= Emax - prec + 1``. If *clamp* is
1052 fixed-width decimal interchange formats specified in IEEE 754.
1103 This method implements the to-number operation of the IBM specification.
1129 Returns a value equal to ``Emin - prec + 1`` which is the minimum exponent
1135 Returns a value equal to ``Emax - prec + 1``.
1382 :meth:`exp` and :meth:`ln` functions. The result is well-defined but
1388 - all three arguments must be integral
1389 - ``y`` must be nonnegative
1390 - at least one of ``x`` or ``y`` must be nonzero
1391 - ``modulo`` must be nonzero and have at most 'precision' digits
1415 The sign of the result, if non-zero, is the same as that of the original
1421 Returns ``x - y * n``, where *n* is the integer nearest the exact value
1447 Square root of a non-negative number to context precision.
1475 .. _decimal-rounding-modes:
1478 ---------
1483 +---------------------+---------------------+-------------------------------+
1484 | | 32-bit | 64-bit |
1487 +---------------------+---------------------+-------------------------------+
1489 +---------------------+---------------------+-------------------------------+
1490 | .. data:: MIN_EMIN | ``-425000000`` | ``-999999999999999999`` |
1491 +---------------------+---------------------+-------------------------------+
1492 | .. data:: MIN_ETINY | ``-849999999`` | ``-1999999999999999997`` |
1493 +---------------------+---------------------+-------------------------------+
1505 the --without-decimal-contextvar option <--without-decimal-contextvar>`,
1506 the C version uses a thread-local rather than a coroutine-local context and the value
1513 --------------
1525 Round towards ``-Infinity``.
1549 .. _decimal-signals:
1552 -------
1584 Signals the division of a non-infinite number by zero.
1588 ``-Infinity`` with the sign determined by the inputs to the calculation.
1595 Signals when non-zero digits were discarded during rounding. The rounded result
1607 Infinity - Infinity
1612 sqrt(-x) and x > 0
1614 x ** (non-integer)
1689 .. _decimal-notes:
1692 --------------------
1695 Mitigating round-off error with increased precision
1700 can still incur round-off error when non-zero digits exceed the fixed precision.
1702 The effects of round-off error can be amplified by the addition or subtraction
1714 >>> u, v, w = Decimal(11111113), Decimal(-11111111), Decimal('7.51111111')
1720 >>> u, v, w = Decimal(20000), Decimal(-6), Decimal('6.0000003')
1732 >>> u, v, w = Decimal(11111113), Decimal(-11111111), Decimal('7.51111111')
1738 >>> u, v, w = Decimal(20000), Decimal(-6), Decimal('6.0000003')
1749 including ``NaN``, ``sNaN``, ``-Infinity``, ``Infinity``,
1750 and two zeros, ``+0`` and ``-0``.
1766 series of computations that occasionally have missing inputs --- it allows the
1774 ``NaN`` is involved. A test for equality where one of the operands is a
1776 ``Decimal('NaN')==Decimal('NaN')``), while a test for inequality always returns
1783 section 5.7). To ensure strict standards-compliance, use the :meth:`~Decimal.compare`
1798 Decimal('0E-1000026')
1803 .. _decimal-threads:
1806 --------------------
1841 .. _decimal-recipes:
1844 -------
1850 pos='', neg='-', trailneg=''):
1859 neg: optional sign for negative numbers: '-', '(', space or blank
1860 trailneg:optional trailing minus indicator: '-', ')', space or blank
1862 >>> d = Decimal('-1234567.8901')
1864 '-$1,234,567.89'
1865 >>> moneyfmt(d, places=0, sep='.', dp='', neg='', trailneg='-')
1866 '1.234.568-'
1871 >>> moneyfmt(Decimal('-0.02'), neg='<', trailneg='>')
1875 q = Decimal(10) ** -places # 2 places --> '0.01'
1915 getcontext().prec -= 2
1939 getcontext().prec -= 2
1961 fact *= i * (i-1)
1963 sign *= -1
1965 getcontext().prec -= 2
1987 fact *= i * (i-1)
1989 sign *= -1
1991 getcontext().prec -= 2
1998 .. _decimal-faq:
2001 -----------
2012 Q. In a fixed-point application with two decimal places, some inputs have many
2019 >>> TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')
2039 non-integer multiplication, will change the number of decimal places and need to
2040 be followed-up with a :meth:`~Decimal.quantize` step:
2042 >>> a = Decimal('102.72') # Initial fixed-point values
2044 >>> a + b # Addition preserves fixed-point
2046 >>> a - b
2050 >>> (a * b).quantize(TWOPLACES) # Must quantize non-integer multiplication
2055 In developing fixed-point applications, it is convenient to define functions
2063 >>> mul(a, b) # Automatically preserve fixed-point
2081 to get a non-exponential representation?
2086 original's two-place significance.
2112 A. The decimal module makes it easy to test results. A best practice is to
2113 re-run calculations using greater precision and with various rounding modes.
2115 ill-conditioned inputs, or a numerically unstable algorithm.
2151 A. Yes. In the CPython and PyPy3 implementations, the C/CFFI versions of
2157 for medium-sized numbers and the `Number Theoretic Transform
2158 <https://en.wikipedia.org/wiki/Discrete_Fourier_transform_(general)#Number-theoretic_transform>`_
2174 For inexact results, :attr:`MAX_PREC` is far too large on 64-bit platforms and
2188 >>> # Maximum number of digits for a single operand using 500MB in 8-byte words
2189 >>> # with 19 digits per word (4-byte and 9 digits for the 32-bit build):
2216 This approach now works for all exact results except for non-integer powers.