Add complex.{__mod__, __rmod__, __divmod__, __rdivmod__}

This commit is contained in:
Jeong YunWon
2019-05-01 02:57:23 +09:00
parent 9523baf5ac
commit 930c8eef50
2 changed files with 42 additions and 0 deletions

View File

@@ -162,6 +162,16 @@ impl PyComplex {
)
}
#[pymethod(name = "__mod__")]
fn mod_(&self, _other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("can't mod complex numbers.".to_string()))
}
#[pymethod(name = "__rmod__")]
fn rmod(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
self.mod_(other, vm)
}
#[pymethod(name = "__floordiv__")]
fn floordiv(&self, _other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("can't take floor of complex number.".to_string()))
@@ -172,6 +182,16 @@ impl PyComplex {
self.floordiv(other, vm)
}
#[pymethod(name = "__divmod__")]
fn divmod(&self, _other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("can't take floor or mod of complex number.".to_string()))
}
#[pymethod(name = "__rdivmod__")]
fn rdivmod(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
self.divmod(other, vm)
}
#[pymethod(name = "__neg__")]
fn neg(&self, _vm: &VirtualMachine) -> Complex64 {
-self.value