File tree 2 files changed +6
-4
lines changed 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 111
111
assert 1.2 .__trunc__ () == 1
112
112
assert int (1.2 ) == 1
113
113
assert float (1.2 ) == 1.2
114
- # assert math.trunc(1.2) == 1
114
+ assert math .trunc (1.2 ) == 1
115
+ assert_raises (OverflowError , float ('inf' ).__trunc__ )
116
+ assert_raises (ValueError , float ('nan' ).__trunc__ )
115
117
116
118
assert (1.7 ).real == 1.7
117
119
assert (1.3 ).is_integer () == False
Original file line number Diff line number Diff line change @@ -377,8 +377,8 @@ impl PyFloat {
377
377
}
378
378
379
379
#[ pymethod( name = "__trunc__" ) ]
380
- fn trunc ( & self , _vm : & VirtualMachine ) -> BigInt {
381
- self . value . to_bigint ( ) . unwrap ( )
380
+ fn trunc ( & self , vm : & VirtualMachine ) -> PyResult < BigInt > {
381
+ try_to_bigint ( self . value , vm )
382
382
}
383
383
384
384
#[ pymethod( name = "__round__" ) ]
@@ -413,7 +413,7 @@ impl PyFloat {
413
413
}
414
414
415
415
#[ pymethod( name = "__int__" ) ]
416
- fn int ( & self , vm : & VirtualMachine ) -> BigInt {
416
+ fn int ( & self , vm : & VirtualMachine ) -> PyResult < BigInt > {
417
417
self . trunc ( vm)
418
418
}
419
419
You can’t perform that action at this time.
0 commit comments