Number methods

Ziga Seilnacht ziga.seilnacht at gmail.com
Sun Jan 21 10:19:00 EST 2007


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:
http://docs.python.org/ref/numeric-types.html

More details can be founf in various PEPs:
http://www.python.org/dev/peps/

> 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:
http://www.python.org/dev/peps/pep-0238/

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_CHECKTYPES in their tp_flags. See:
http://docs.python.org/ref/coercion-rules.html
and
http://www.python.org/dev/peps/pep-0208/
for details.

Ziga




More information about the Python-list mailing list