mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Merged revisions 59666-59679 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
This commit is contained in:
parent
1c9f4373d2
commit
072c0f1b7e
32 changed files with 383 additions and 83 deletions
|
@ -915,10 +915,13 @@ available. They are listed here in alphabetical order.
|
|||
.. function:: round(x[, n])
|
||||
|
||||
Return the floating point value *x* rounded to *n* digits after the decimal
|
||||
point. If *n* is omitted, it defaults to zero. The result is a floating point
|
||||
number. Values are rounded to the closest multiple of 10 to the power minus
|
||||
*n*; if two multiples are equally close, rounding is done away from 0 (so. for
|
||||
example, ``round(0.5)`` is ``1.0`` and ``round(-0.5)`` is ``-1.0``).
|
||||
point. If *n* is omitted, it defaults to zero. Values are rounded to the
|
||||
closest multiple of 10 to the power minus *n*; if two multiples are equally
|
||||
close, rounding is done toward the even choice (so, for example, both
|
||||
``round(0.5)`` and ``round(-0.5)`` are ``0``, and ``round(1.5)`` is
|
||||
``2``). Delegates to ``x.__round__(n)``.
|
||||
|
||||
.. versionchanged:: 2.6
|
||||
|
||||
|
||||
.. function:: set([iterable])
|
||||
|
@ -1064,6 +1067,14 @@ available. They are listed here in alphabetical order.
|
|||
operators such as ``super(C, self)[name]``.
|
||||
|
||||
|
||||
.. function:: trunc(x)
|
||||
|
||||
Return the :class:`Real` value *x* truncated to an :class:`Integral` (usually
|
||||
a long integer). Delegates to ``x.__trunc__()``.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
|
||||
|
||||
.. function:: tuple([iterable])
|
||||
|
||||
Return a tuple whose items are the same and in the same order as *iterable*'s
|
||||
|
|
|
@ -26,8 +26,17 @@ Number-theoretic and representation functions:
|
|||
|
||||
.. function:: ceil(x)
|
||||
|
||||
Return the ceiling of *x* as a float, the smallest integer value greater than or
|
||||
equal to *x*.
|
||||
Return the ceiling of *x* as a float, the smallest integer value greater than
|
||||
or equal to *x*. If *x* is not a float, delegates to ``x.__ceil__()``, which
|
||||
should return an :class:`Integral` value.
|
||||
|
||||
|
||||
.. function:: copysign(x, y)
|
||||
|
||||
Return *x* with the sign of *y*. ``copysign`` copies the sign bit of an IEEE
|
||||
754 float, ``copysign(1, -0.0)`` returns *-1.0*.
|
||||
|
||||
..versionadded:: 2.6
|
||||
|
||||
|
||||
.. function:: fabs(x)
|
||||
|
@ -37,8 +46,9 @@ Number-theoretic and representation functions:
|
|||
|
||||
.. function:: floor(x)
|
||||
|
||||
Return the floor of *x* as a float, the largest integer value less than or equal
|
||||
to *x*.
|
||||
Return the floor of *x* as a float, the largest integer value less than or
|
||||
equal to *x*. If *x* is not a float, delegates to ``x.__floor__()``, which
|
||||
should return an :class:`Integral` value.
|
||||
|
||||
|
||||
.. function:: fmod(x, y)
|
||||
|
@ -64,6 +74,23 @@ Number-theoretic and representation functions:
|
|||
apart" the internal representation of a float in a portable way.
|
||||
|
||||
|
||||
.. function:: isinf(x)
|
||||
|
||||
Checks if the float *x* is positive or negative infinite.
|
||||
|
||||
..versionadded:: 2.6
|
||||
|
||||
|
||||
.. function:: isnan(x)
|
||||
|
||||
Checks if the float *x* is a NaN (not a number). NaNs are part of the
|
||||
IEEE 754 standards. Operation like but not limited to ``inf * 0``,
|
||||
``inf / inf`` or any operation involving a NaN, e.g. ``nan * 1``, return
|
||||
a NaN.
|
||||
|
||||
..versionadded:: 2.6
|
||||
|
||||
|
||||
.. function:: ldexp(x, i)
|
||||
|
||||
Return ``x * (2**i)``. This is essentially the inverse of function
|
||||
|
|
99
Doc/library/numbers.rst
Normal file
99
Doc/library/numbers.rst
Normal file
|
@ -0,0 +1,99 @@
|
|||
|
||||
:mod:`numbers` --- Numeric abstract base classes
|
||||
================================================
|
||||
|
||||
.. module:: numbers
|
||||
:synopsis: Numeric abstract base classes (Complex, Real, Integral, etc.).
|
||||
|
||||
The :mod:`numbers` module (:pep:`3141`) defines a hierarchy of numeric abstract
|
||||
base classes which progressively define more operations. These concepts also
|
||||
provide a way to distinguish exact from inexact types. None of the types defined
|
||||
in this module can be instantiated.
|
||||
|
||||
|
||||
.. class:: Number
|
||||
|
||||
The root of the numeric hierarchy. If you just want to check if an argument
|
||||
*x* is a number, without caring what kind, use ``isinstance(x, Number)``.
|
||||
|
||||
|
||||
Exact and inexact operations
|
||||
----------------------------
|
||||
|
||||
.. class:: Exact
|
||||
|
||||
Subclasses of this type have exact operations.
|
||||
|
||||
As long as the result of a homogenous operation is of the same type, you can
|
||||
assume that it was computed exactly, and there are no round-off errors. Laws
|
||||
like commutativity and associativity hold.
|
||||
|
||||
|
||||
.. class:: Inexact
|
||||
|
||||
Subclasses of this type have inexact operations.
|
||||
|
||||
Given X, an instance of :class:`Inexact`, it is possible that ``(X + -X) + 3
|
||||
== 3``, but ``X + (-X + 3) == 0``. The exact form this error takes will vary
|
||||
by type, but it's generally unsafe to compare this type for equality.
|
||||
|
||||
|
||||
The numeric tower
|
||||
-----------------
|
||||
|
||||
.. class:: Complex
|
||||
|
||||
Subclasses of this type describe complex numbers and include the operations
|
||||
that work on the builtin :class:`complex` type. These are: conversions to
|
||||
:class:`complex` and :class:`bool`, :attr:`.real`, :attr:`.imag`, ``+``,
|
||||
``-``, ``*``, ``/``, :func:`abs`, :meth:`conjugate`, ``==``, and ``!=``. All
|
||||
except ``-`` and ``!=`` are abstract.
|
||||
|
||||
.. attribute:: Complex.real
|
||||
|
||||
Abstract. Retrieves the :class:`Real` component of this number.
|
||||
|
||||
.. attribute:: Complex.imag
|
||||
|
||||
Abstract. Retrieves the :class:`Real` component of this number.
|
||||
|
||||
.. method:: Complex.conjugate()
|
||||
|
||||
Abstract. Returns the complex conjugate. For example, ``(1+3j).conjugate() ==
|
||||
(1-3j)``.
|
||||
|
||||
.. class:: Real
|
||||
|
||||
To :class:`Complex`, :class:`Real` adds the operations that work on real
|
||||
numbers.
|
||||
|
||||
In short, those are: a conversion to :class:`float`, :func:`trunc`,
|
||||
:func:`round`, :func:`math.floor`, :func:`math.ceil`, :func:`divmod`, ``//``,
|
||||
``%``, ``<``, ``<=``, ``>``, and ``>=``.
|
||||
|
||||
Real also provides defaults for :func:`complex`, :attr:`Complex.real`,
|
||||
:attr:`Complex.imag`, and :meth:`Complex.conjugate`.
|
||||
|
||||
|
||||
.. class:: Rational
|
||||
|
||||
Subtypes both :class:`Real` and :class:`Exact`, and adds
|
||||
:attr:`Rational.numerator` and :attr:`Rational.denominator` properties, which
|
||||
should be in lowest terms. With these, it provides a default for
|
||||
:func:`float`.
|
||||
|
||||
.. attribute:: Rational.numerator
|
||||
|
||||
Abstract.
|
||||
|
||||
.. attribute:: Rational.denominator
|
||||
|
||||
Abstract.
|
||||
|
||||
|
||||
.. class:: Integral
|
||||
|
||||
Subtypes :class:`Rational` and adds a conversion to :class:`long`, the
|
||||
3-argument form of :func:`pow`, and the bit-string operations: ``<<``,
|
||||
``>>``, ``&``, ``^``, ``|``, ``~``. Provides defaults for :func:`float`,
|
||||
:attr:`Rational.numerator`, and :attr:`Rational.denominator`.
|
|
@ -6,16 +6,18 @@ Numeric and Mathematical Modules
|
|||
********************************
|
||||
|
||||
The modules described in this chapter provide numeric and math-related functions
|
||||
and data types. The :mod:`math` and :mod:`cmath` contain various mathematical
|
||||
functions for floating-point and complex numbers. For users more interested in
|
||||
decimal accuracy than in speed, the :mod:`decimal` module supports exact
|
||||
representations of decimal numbers.
|
||||
and data types. The :mod:`numbers` module defines an abstract hierarchy of
|
||||
numeric types. The :mod:`math` and :mod:`cmath` modules contain various
|
||||
mathematical functions for floating-point and complex numbers. For users more
|
||||
interested in decimal accuracy than in speed, the :mod:`decimal` module supports
|
||||
exact representations of decimal numbers.
|
||||
|
||||
The following modules are documented in this chapter:
|
||||
|
||||
|
||||
.. toctree::
|
||||
|
||||
numbers.rst
|
||||
math.rst
|
||||
cmath.rst
|
||||
decimal.rst
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue