Number methods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Maclaren

    #1

    Number methods


    I can't find any description of these. Most are obvious, but some
    are not. Note that this is from the point of view of IMPLEMENTING
    them, not USING them. Specifically:

    Does Python use classic division (nb_divide) and inversion (nb_invert)
    or are they entirely historical? Note that I can very easily provide
    the latter.

    Is there any documentation on the coercion function (nb_coerce)? It
    seems to have unusual properties.

    Thanks for any hints.


    Regards,
    Nick Maclaren.
  • Ziga Seilnacht

    #2
    Re: Number methods

    Nick Maclaren wrote:
    I can't find any description of these. Most are obvious, but some
    are not. Note that this is from the point of view of IMPLEMENTING
    them, not USING them. Specifically:
    The Python equivalents of these methods are described in the
    reference manual:


    More details can be founf in various PEPs:
    This PEP contains the index of all Python Enhancement Proposals, known as PEPs. PEP numbers are assigned by the PEP editors, and once assigned are never changed. The version control history of the PEP texts represent their historical record.

    Does Python use classic division (nb_divide) and inversion (nb_invert)
    or are they entirely historical? Note that I can very easily provide
    the latter.
    Python uses classic divison by default. True divison is used only when
    the division __future__ directive is in effect. See PEP 238 for
    details:
    The current division (/) operator has an ambiguous meaning for numerical arguments: it returns the floor of the mathematical result of division if the arguments are ints or longs, but it returns a reasonable approximation of the division result if the a...


    The nb_invert method is used for the implementation of the bitwise
    inverse unary operator (~). I don't think that it is deprecated. See:
    http://docs.python.org/lib/bitstring-ops.html for details.
    Is there any documentation on the coercion function (nb_coerce)? It
    seems to have unusual properties.
    It is used for old style Python classes and extension types that
    don't have Py_TPFLAGS_CHEC KTYPES in their tp_flags. See:

    and
    Many Python types implement numeric operations. When the arguments of a numeric operation are of different types, the interpreter tries to coerce the arguments into a common type. The numeric operation is then performed using this common type. This P...

    for details.

    Ziga

    Comment

    Working...