Fix edge cases in mod and complex division

This commit is contained in:
carbotaniuman committed 2020-11-11 14:33:07 -06:00
1 parent c478c64e2e
commit ace2cb8f2f
3 files changed
+6 -5

No files matched your search

-3
View File
@@ -323,8 +323,6 @@ class FractionTest(unittest.TestCase):
ValueError, "max_denominator should be at least 1",
F(1).limit_denominator, i)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def testConversions(self):
self.assertTypedEquals(-1, math.trunc(F(-11, 10)))
self.assertTypedEquals(1, math.trunc(F(11, 10)))
@@ -459,7 +457,6 @@ class FractionTest(unittest.TestCase):
)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def testMixedArithmetic(self):
self.assertTypedEquals(F(11, 10), F(1, 10) + 1)
self.assertTypedEquals(1.1, F(1, 10) + 1.0)
+5 -1
View File
@@ -182,7 +182,11 @@ pub fn div(v1: f64, v2: f64) -> Option<f64> {
pub fn mod_(v1: f64, v2: f64) -> Option<f64> {
if v2 != 0.0 {
Some(v1 % v2)
let mut val = v1 % v2;
if (val < 0.0) != (v2 < 0.0) {
val += v2;
}
Some(val)
} else {
None
}
+1 -1
View File
@@ -180,7 +180,7 @@ impl PyComplex {
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmaticValue<Complex64>> {
self.op(other, |a, b| a / b, vm)
self.op(other, |a, b| a.fdiv(b), vm)
}
#[pymethod(name = "__rtruediv__")]