Skip to content

Commit ace2cb8

Browse files
committed
Fix edge cases in mod and complex division
1 parent c478c64 commit ace2cb8

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Lib/test/test_fractions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,6 @@ def testLimitDenominator(self):
323323
ValueError, "max_denominator should be at least 1",
324324
F(1).limit_denominator, i)
325325

326-
# TODO: RUSTPYTHON
327-
@unittest.expectedFailure
328326
def testConversions(self):
329327
self.assertTypedEquals(-1, math.trunc(F(-11, 10)))
330328
self.assertTypedEquals(1, math.trunc(F(11, 10)))
@@ -459,7 +457,6 @@ def testLargeArithmetic(self):
459457
)
460458

461459
# TODO: RUSTPYTHON
462-
@unittest.expectedFailure
463460
def testMixedArithmetic(self):
464461
self.assertTypedEquals(F(11, 10), F(1, 10) + 1)
465462
self.assertTypedEquals(1.1, F(1, 10) + 1.0)

common/src/float_ops.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ pub fn div(v1: f64, v2: f64) -> Option<f64> {
182182

183183
pub fn mod_(v1: f64, v2: f64) -> Option<f64> {
184184
if v2 != 0.0 {
185-
Some(v1 % v2)
185+
let mut val = v1 % v2;
186+
if (val < 0.0) != (v2 < 0.0) {
187+
val += v2;
188+
}
189+
Some(val)
186190
} else {
187191
None
188192
}

vm/src/builtins/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl PyComplex {
180180
other: PyObjectRef,
181181
vm: &VirtualMachine,
182182
) -> PyResult<PyArithmaticValue<Complex64>> {
183-
self.op(other, |a, b| a / b, vm)
183+
self.op(other, |a, b| a.fdiv(b), vm)
184184
}
185185

186186
#[pymethod(name = "__rtruediv__")]

0 commit comments

Comments
 (0)