File tree Expand file tree Collapse file tree 3 files changed +8
-6
lines changed
Expand file tree Collapse file tree 3 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -347,8 +347,6 @@ def test_float_ceil(self):
347347 self .assertRaises (OverflowError , float ("inf" ).__ceil__ )
348348 self .assertRaises (OverflowError , float ("-inf" ).__ceil__ )
349349
350- # TODO: RUSTPYTHON
351- @unittest .expectedFailure
352350 @support .requires_IEEE_754
353351 def test_float_mod (self ):
354352 # Check behaviour of % operator for IEEE 754 special cases.
Original file line number Diff line number Diff line change @@ -336,11 +336,12 @@ pub fn div(v1: f64, v2: f64) -> Option<f64> {
336336
337337pub fn mod_ ( v1 : f64 , v2 : f64 ) -> Option < f64 > {
338338 if v2 != 0.0 {
339- let mut val = v1 % v2;
340- if ( val < 0.0 ) != ( v2 < 0.0 ) {
341- val += v2;
339+ let val = v1 % v2;
340+ match ( v1. signum ( ) as i32 , v2. signum ( ) as i32 ) {
341+ ( 1 , 1 ) | ( -1 , -1 ) => Some ( val) ,
342+ _ if ( v1 == 0.0 ) || ( v1. abs ( ) == v2. abs ( ) ) => Some ( val. copysign ( v2) ) ,
343+ _ => Some ( ( val + v2) . copysign ( v2) ) ,
342344 }
343- Some ( val)
344345 } else {
345346 None
346347 }
Original file line number Diff line number Diff line change @@ -513,3 +513,6 @@ def identical(x, y):
513513assert_raises (ValueError , lambda : float ('0._' ))
514514assert_raises (ValueError , lambda : float ('_.0' ))
515515assert_raises (ValueError , lambda : float ('._0' ))
516+
517+ assert 3.0 % - 2.0 == - 1.0
518+ assert - 3.0 % 2.0 == 1.0
You can’t perform that action at this time.
0 commit comments