pub trait NumberProtocol: ObjectProtocol {
Show 22 methods
// Provided 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§
Sourcefn add(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
fn add(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
Perform addition (self + other)
Invokes the __add__
magic-method
Sourcefn subtract(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
fn subtract(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
Perform subtraction (self - other)
Invokes the __sub__
magic-method
Sourcefn multiply(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
fn multiply(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
Perform multiplication (self * other)
Invokes the __mul__
magic-method
Sourcefn matrix_multiply(
&self,
py: Python<'_>,
other: impl ToPyObject,
) -> PyResult<PyObject>
fn matrix_multiply( &self, py: Python<'_>, other: impl ToPyObject, ) -> PyResult<PyObject>
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.
Sourcefn power(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
fn power(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
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.
Sourcefn power_modulo(
&self,
py: Python<'_>,
exp: impl ToPyObject,
z: impl ToPyObject,
) -> PyResult<PyObject>
fn power_modulo( &self, py: Python<'_>, exp: impl ToPyObject, z: impl ToPyObject, ) -> PyResult<PyObject>
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
Sourcefn true_divide(
&self,
py: Python<'_>,
other: impl ToPyObject,
) -> PyResult<PyObject>
fn true_divide( &self, py: Python<'_>, other: impl ToPyObject, ) -> PyResult<PyObject>
Perform the “true division” operation,
equivalent to the Python expression self / other
,
Invokes the __truediv__
magic-method.
Sourcefn floor_divide(
&self,
py: Python<'_>,
other: impl ToPyObject,
) -> PyResult<PyObject>
fn floor_divide( &self, py: Python<'_>, other: impl ToPyObject, ) -> PyResult<PyObject>
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.
Sourcefn modulo(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
fn modulo(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
Return the remainder of dividing self
by other
,
equivalent to the Python expression self % other
Invokes the __mod__
magic-method.
Sourcefn div_mod(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
fn div_mod(&self, py: Python<'_>, other: impl ToPyObject) -> PyResult<PyObject>
Perform combined division and modulo,
equivalent to the builtin method divmod(self, other)
Invokes the __divmod__
magic-method.
Sourcefn negative(&self, py: Python<'_>) -> PyResult<PyObject>
fn negative(&self, py: Python<'_>) -> PyResult<PyObject>
Perform the negation of self (-self)
Invokes the __neg__
magic-method.
Sourcefn positive(&self, py: Python<'_>) -> PyResult<PyObject>
fn positive(&self, py: Python<'_>) -> PyResult<PyObject>
Invoke the ‘positive’ operation, equivalent to the
Python expression +self
Invokes the __pos__
magic-method
Sourcefn absolute(&self, py: Python<'_>) -> PyResult<PyObject>
fn absolute(&self, py: Python<'_>) -> PyResult<PyObject>
Return the absolute value of self,
equivalent to calling the builtin function abs
Invokes the __abs__
magic-method.
Sourcefn bitwise_invert(&self, py: Python<'_>) -> PyResult<PyObject>
fn bitwise_invert(&self, py: Python<'_>) -> PyResult<PyObject>
Perform the bitwise negation of self,
equivalent to the Python expression ~self
Invokes the __invert__
magic-method
Sourcefn left_shift(
&self,
py: Python<'_>,
bits: impl ToPyObject,
) -> PyResult<PyObject>
fn left_shift( &self, py: Python<'_>, bits: impl ToPyObject, ) -> PyResult<PyObject>
Shift this value to the left by the specified number of bits,
equivalent to the Python expression self << bits
Invokes the __lshift__
magic-method
Sourcefn right_shift(
&self,
py: Python<'_>,
bits: impl ToPyObject,
) -> PyResult<PyObject>
fn right_shift( &self, py: Python<'_>, bits: impl ToPyObject, ) -> PyResult<PyObject>
Shift this value to the right by the specified number of bits,
equivalent to the Python expression self >> bits
Invokes the __rshift__
magic-method
Sourcefn bitwise_and(
&self,
py: Python<'_>,
other: impl ToPyObject,
) -> PyResult<PyObject>
fn bitwise_and( &self, py: Python<'_>, other: impl ToPyObject, ) -> PyResult<PyObject>
Perform the “bitwise and” of self & other
Invokes the __and__
magic-method.
Sourcefn bitwise_xor(
&self,
py: Python<'_>,
other: impl ToPyObject,
) -> PyResult<PyObject>
fn bitwise_xor( &self, py: Python<'_>, other: impl ToPyObject, ) -> PyResult<PyObject>
Perform the “bitwise exclusive or”,
equivalent to Python expression self ^ other
Invokes the __xor__
magic-method.
Sourcefn bitwise_or(
&self,
py: Python<'_>,
other: impl ToPyObject,
) -> PyResult<PyObject>
fn bitwise_or( &self, py: Python<'_>, other: impl ToPyObject, ) -> PyResult<PyObject>
Perform the “bitwise or” of self | other
Invokes the __or__
magic-method.
Sourcefn to_int(&self, py: Python<'_>) -> PyResult<PyLong>
fn to_int(&self, py: Python<'_>) -> PyResult<PyLong>
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.
Sourcefn to_float(&self, py: Python<'_>) -> PyResult<PyFloat>
fn to_float(&self, py: Python<'_>) -> PyResult<PyFloat>
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.