pub trait NumberProtocol: ObjectProtocol {
Show 22 methods fn add(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject> { ... } fn subtract(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn multiply(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn matrix_multiply(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn power(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject> { ... } fn power_modulo(
        &self,
        py: Python<'_>,
        exp: impl ToPyObject,
        z: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn true_divide(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn floor_divide(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn modulo(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject> { ... } fn div_mod(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn negative(&self, py: Python<'_>) -> PyResult<PyObject> { ... } fn positive(&self, py: Python<'_>) -> PyResult<PyObject> { ... } fn absolute(&self, py: Python<'_>) -> PyResult<PyObject> { ... } fn bitwise_invert(&self, py: Python<'_>) -> PyResult<PyObject> { ... } fn left_shift(
        &self,
        py: Python<'_>,
        bits: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn right_shift(
        &self,
        py: Python<'_>,
        bits: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn bitwise_and(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn bitwise_xor(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn bitwise_or(
        &self,
        py: Python<'_>,
        other: impl ToPyObject
    ) -> PyResult<PyObject> { ... } fn to_int(&self, py: Python<'_>) -> PyResult<PyLong> { ... } fn to_float(&self, py: Python<'_>) -> PyResult<PyFloat> { ... } fn to_index(&self, py: Python<'_>) -> PyResult<PyLong> { ... }
}
Expand description

Operations on numeric objects

Provided Methods

Perform addition (self + other)

Invokes the __add__ magic-method

Perform subtraction (self - other)

Invokes the __sub__ magic-method

Perform multiplication (self * other)

Invokes the __mul__ magic-method

Perform matrix multiplication, equivalent to the Python expression self @ other

Invokes the __matmul__ magic-method

This method is only available with Python 3.

See PEP 0456 for details.

Perform exponentiation, equivalent to the Python expression self ** other, or the two-argument form of the builtin method pow: pow(self, other)

Invokes the __pow__ magic-method

See also NumberProtocol::power_modulo.

Perform exponentiation modulo an integer, mathematically equivalent to self ** other % mod but computed much more efficiently.

Equivalent to invoking the three-argument form of the builtin pow method: pow(self, other, z)

Invoking with a None for modulo is equivalent to the regular power operation.

Invokes the __pow__ magic-method

Perform the “true division” operation, equivalent to the Python expression self / other,

Invokes the __truediv__ magic-method.

Perform the “floor division” operation, equivalent to the Python expression self // other,

This method was added in Python 3. If compiling against Python 2, it unconditional throws an error.

Invokes the __floordiv__ magic-method.

Return the remainder of dividing self by other, equivalent to the Python expression self % other

Invokes the __mod__ magic-method.

Perform combined division and modulo, equivalent to the builtin method divmod(self, other)

Invokes the __divmod__ magic-method.

Perform the negation of self (-self)

Invokes the __neg__ magic-method.

Invoke the ‘positive’ operation, equivalent to the Python expression +self

Invokes the __pos__ magic-method

Return the absolute value of self, equivalent to calling the builtin function abs

Invokes the __abs__ magic-method.

Perform the bitwise negation of self, equivalent to the Python expression ~self

Invokes the __invert__ magic-method

Shift this value to the left by the specified number of bits, equivalent to the Python expression self << bits

Invokes the __lshift__ magic-method

Shift this value to the right by the specified number of bits, equivalent to the Python expression self >> bits

Invokes the __rshift__ magic-method

Perform the “bitwise and” of self & other

Invokes the __and__ magic-method.

Perform the “bitwise exclusive or”, equivalent to Python expression self ^ other

Invokes the __xor__ magic-method.

Perform the “bitwise or” of self | other

Invokes the __or__ magic-method.

Convert this object to an integer, equivalent to the builtin function int(self)

Invokes the __int__ magic-method.

Throws an exception if unable to perform the conversion.

Convert this object to a float, equivalent to the builtin function float(self)

Invokes the __float__ magic-method.

Throws an exception if unable to perform the conversion.

Losslessly convert this object to an integer index, as if calling operator.index()

The presence of this method indicates this object is an integer type.

Calls the __index__ magic-method.

See also: Documentation on the corresponding magic-method

Implementors