File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -173,8 +173,6 @@ def test_infinity_and_nan_constants(self):
173173 self .assertEqual (repr (cmath .nan ), "nan" )
174174 self .assertEqual (repr (cmath .nanj ), "nanj" )
175175
176- # TODO: RUSTPYTHON see TODO in cmath_log.
177- @unittest .expectedFailure
178176 def test_user_object (self ):
179177 # Test automatic calling of __complex__ and __float__ by cmath
180178 # functions
@@ -536,8 +534,6 @@ def test_abs(self):
536534 self .assertEqual (abs (complex (INF , NAN )), INF )
537535 self .assertTrue (math .isnan (abs (complex (NAN , NAN ))))
538536
539- # TODO: RUSTPYTHON
540- @unittest .expectedFailure
541537 @requires_IEEE_754
542538 def test_abs_overflows (self ):
543539 # result overflows
Original file line number Diff line number Diff line change @@ -228,9 +228,15 @@ impl PyComplex {
228228 }
229229
230230 #[ pymethod( magic) ]
231- fn abs ( & self ) -> f64 {
231+ fn abs ( & self , vm : & VirtualMachine ) -> PyResult < f64 > {
232232 let Complex64 { im, re } = self . value ;
233- re. hypot ( im)
233+ let is_finite = im. is_finite ( ) && re. is_finite ( ) ;
234+ let abs_result = re. hypot ( im) ;
235+ if is_finite && abs_result. is_infinite ( ) {
236+ Err ( vm. new_overflow_error ( "absolute value too large" . to_string ( ) ) )
237+ } else {
238+ Ok ( abs_result)
239+ }
234240 }
235241
236242 #[ inline]
@@ -402,7 +408,15 @@ impl Comparable for PyComplex {
402408 ) -> PyResult < PyComparisonValue > {
403409 op. eq_only ( || {
404410 let result = if let Some ( other) = other. payload_if_subclass :: < PyComplex > ( vm) {
405- zelf. value == other. value
411+ if zelf. value . re . is_nan ( )
412+ && zelf. value . im . is_nan ( )
413+ && other. value . re . is_nan ( )
414+ && other. value . im . is_nan ( )
415+ {
416+ true
417+ } else {
418+ zelf. value == other. value
419+ }
406420 } else {
407421 match float:: to_op_float ( other, vm) {
408422 Ok ( Some ( other) ) => zelf. value == other. into ( ) ,
You can’t perform that action at this time.
0 commit comments