mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-17 01:51:39 +09:00
Add int and float methods for the complex type
This commit is contained in:
@@ -161,12 +161,22 @@ impl PyComplex {
|
||||
vm.ctx.new_bool(result)
|
||||
}
|
||||
|
||||
#[pymethod(name = "__float__")]
|
||||
fn float(&self, vm: &VirtualMachine) -> PyResult {
|
||||
return Err(vm.new_type_error(String::from("Can't convert complex to float")));
|
||||
}
|
||||
|
||||
#[pymethod(name = "__int__")]
|
||||
fn int(&self, vm: &VirtualMachine) -> PyResult {
|
||||
return Err(vm.new_type_error(String::from("Can't convert complex to int")));
|
||||
}
|
||||
|
||||
#[pymethod(name = "__mul__")]
|
||||
fn mul(self, other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
fn mul(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
match to_complex(other, vm) {
|
||||
Ok(Some(other)) => Ok(vm.ctx.new_complex(Complex64::new(
|
||||
self.value.re * other.re - self.value.im * other.im,
|
||||
self.value.re * other.im + self.value.re * other.im,
|
||||
self.value.re * other.im + self.value.im * other.re,
|
||||
))),
|
||||
Ok(None) => Ok(vm.ctx.not_implemented()),
|
||||
Err(err) => Err(err),
|
||||
|
||||
Reference in New Issue
Block a user