summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-06-21 17:30:06 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2008-06-21 17:30:06 (GMT)
commit8e1c52ac0e551505f0edb4aad2774c37e1d93ea5 (patch)
tree1cb5aa188be31598b1403036f960eb93cda5bc16
parent924b823a601fca89d2a0b340928caa4a965de509 (diff)
downloadcpython-8e1c52ac0e551505f0edb4aad2774c37e1d93ea5.zip
cpython-8e1c52ac0e551505f0edb4aad2774c37e1d93ea5.tar.gz
cpython-8e1c52ac0e551505f0edb4aad2774c37e1d93ea5.tar.bz2
Reviewed and updated the documentation. Fixes #3017.
-rw-r--r--Doc/library/decimal.rst250
1 files changed, 241 insertions, 9 deletions
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
index 3359703..330f139 100644
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -140,6 +140,7 @@ representation error). Decimal numbers include special values such as
:const:`NaN` which stands for "Not a number", positive and negative
:const:`Infinity`, and :const:`-0`.
+ >>> getcontext().prec = 28
>>> Decimal(10)
Decimal('10')
>>> Decimal('3.14')
@@ -206,6 +207,7 @@ floating point flying circus:
And some mathematical functions are also available to Decimal:
+ >>> getcontext().prec = 28
>>> Decimal(2).sqrt()
Decimal('1.414213562373095048801688724')
>>> Decimal(1).exp()
@@ -434,6 +436,13 @@ Decimal objects
.. versionadded:: 2.6
+ .. method:: conjugate()
+
+ Just returns self, this method is only to comply with the Decimal
+ Specification.
+
+ .. versionadded:: 2.6
+
.. method:: copy_abs()
Return the absolute value of the argument. This operation is unaffected
@@ -812,15 +821,6 @@ Decimal objects
renamed from ``to_integral`` to ``to_integral_value``. The old name
remains valid for compatibility.
- .. method:: trim()
-
- Return the decimal with *insignificant* trailing zeros removed. Here, a
- trailing zero is considered insignificant either if it follows the decimal
- point, or if the exponent of the argument (that is, the last element of
- the :meth:`as_tuple` representation) is positive.
-
- .. versionadded:: 2.6
-
.. _logical_operands_label:
Logical operands
@@ -1036,6 +1036,46 @@ In addition to the three supplied contexts, new contexts can be created with the
Return the sum of *x* and *y*.
+ .. method:: canonical(x)
+
+ Returns the same Decimal object *x*.
+
+
+ .. method:: compare(x, y)
+
+ Compares *x* and *y* numerically.
+
+
+ .. method:: compare_signal(x, y)
+
+ Compares the values of the two operands numerically.
+
+
+ .. method:: compare_total(x, y)
+
+ Compares two operands using their abstract representation.
+
+
+ .. method:: compare_total_mag(x, y)
+
+ Compares two operands using their abstract representation, ignoring sign.
+
+
+ .. method:: copy_abs(x)
+
+ Returns a copy of *x* with the sign set to 0.
+
+
+ .. method:: copy_negate(x)
+
+ Returns a copy of *x* with the sign inverted.
+
+
+ .. method:: copy_sign(x, y)
+
+ Copies the sign from *y* to *x*.
+
+
.. method:: divide(x, y)
Return *x* divided by *y*.
@@ -1051,6 +1091,121 @@ In addition to the three supplied contexts, new contexts can be created with the
Divides two numbers and returns the integer part of the result.
+ .. method:: exp(x)
+
+ Returns `e ** x`.
+
+
+ .. method:: fma(x, y, z)
+
+ Returns *x* multiplied by *y*, plus *z*.
+
+
+ .. method:: is_canonical(x)
+
+ Returns True if *x* is canonical; otherwise returns False.
+
+
+ .. method:: is_finite(x)
+
+ Returns True if *x* is finite; otherwise returns False.
+
+
+ .. method:: is_infinite(x)
+
+ Returns True if *x* is infinite; otherwise returns False.
+
+
+ .. method:: is_nan(x)
+
+ Returns True if *x* is a qNaN or sNaN; otherwise returns False.
+
+
+ .. method:: is_normal(x)
+
+ Returns True if *x* is a normal number; otherwise returns False.
+
+
+ .. method:: is_qnan(x)
+
+ Returns True if *x* is a quiet NaN; otherwise returns False.
+
+
+ .. method:: is_signed(x)
+
+ Returns True if *x* is negative; otherwise returns False.
+
+
+ .. method:: is_snan(x)
+
+ Returns True if *x* is a signaling NaN; otherwise returns False.
+
+
+ .. method:: is_subnormal(x)
+
+ Returns True if *x* is subnormal; otherwise returns False.
+
+
+ .. method:: is_zero(x)
+
+ Returns True if *x* is a zero; otherwise returns False.
+
+
+ .. method:: ln(x)
+
+ Returns the natural (base e) logarithm of *x*.
+
+
+ .. method:: log10(x)
+
+ Returns the base 10 logarithm of *x*.
+
+
+ .. method:: logb(x)
+
+ Returns the exponent of the magnitude of the operand's MSD.
+
+
+ .. method:: logical_and(x, y)
+
+ Applies the logical operation `and` between each operand's digits.
+
+
+ .. method:: logical_invert(x)
+
+ Invert all the digits in *x*.
+
+
+ .. method:: logical_or(x, y)
+
+ Applies the logical operation `or` between each operand's digits.
+
+
+ .. method:: logical_xor(x, y)
+
+ Applies the logical operation `xor` between each operand's digits.
+
+
+ .. method:: max(x, y)
+
+ Compares two values numerically and returns the maximum.
+
+
+ .. method:: max_mag(x, y)
+
+ Compares the values numerically with their sign ignored.
+
+
+ .. method:: min(x, y)
+
+ Compares two values numerically and returns the minimum.
+
+
+ .. method:: min_mag(x, y)
+
+ Compares the values numerically with their sign ignored.
+
+
.. method:: minus(x)
Minus corresponds to the unary prefix minus operator in Python.
@@ -1061,6 +1216,31 @@ In addition to the three supplied contexts, new contexts can be created with the
Return the product of *x* and *y*.
+ .. method:: next_minus(x)
+
+ Returns the largest representable number smaller than *x*.
+
+
+ .. method:: next_plus(x)
+
+ Returns the smallest representable number larger than *x*.
+
+
+ .. method:: next_toward(x, y)
+
+ Returns the number closest to *x*, in direction towards *y*.
+
+
+ .. method:: normalize(x)
+
+ Reduces *x* to its simplest form.
+
+
+ .. method:: number_class(x)
+
+ Returns an indication of the class of *x*.
+
+
.. method:: plus(x)
Plus corresponds to the unary prefix plus operator in Python. This
@@ -1095,6 +1275,16 @@ In addition to the three supplied contexts, new contexts can be created with the
Stricter requirements for the three-argument version.
+ .. method:: quantize(x, y)
+
+ Returns a value equal to *x* (rounded), having the exponent of *y*.
+
+
+ .. method:: radix()
+
+ Just returns 10, as this is Decimal, :)
+
+
.. method:: remainder(x, y)
Returns the remainder from integer division.
@@ -1102,10 +1292,52 @@ In addition to the three supplied contexts, new contexts can be created with the
The sign of the result, if non-zero, is the same as that of the original
dividend.
+ .. method:: remainder_near(x, y)
+
+ Returns `x - y * n`, where *n* is the integer nearest the exact value
+ of `x / y` (if the result is `0` then its sign will be the sign of *x*).
+
+
+ .. method:: rotate(x, y)
+
+ Returns a rotated copy of *x*, *y* times.
+
+
+ .. method:: same_quantum(x, y)
+
+ Returns True if the two operands have the same exponent.
+
+
+ .. method:: scaleb (x, y)
+
+ Returns the first operand after adding the second value its exp.
+
+
+ .. method:: shift(x, y)
+
+ Returns a shifted copy of *x*, *y* times.
+
+
+ .. method:: sqrt(x)
+
+ Square root of a non-negative number to context precision.
+
+
.. method:: subtract(x, y)
Return the difference between *x* and *y*.
+
+ .. method:: to_eng_string(x)
+
+ Converts a number to a string, using scientific notation.
+
+
+ .. method:: to_integral_exact(x)
+
+ Rounds to an integer.
+
+
.. method:: to_sci_string(x)
Converts a number to a string using scientific notation.