File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 61
61
with assert_raises (ZeroDivisionError ):
62
62
(0 ).__rmod__ (10 )
63
63
64
+ # as_integer_ratio
65
+ # TODO uncomment the following tests once #1705 lands (or when the CPython version in test pipeline is upgraded to 3.8)
66
+ # assert (42).as_integer_ratio() == (42, 1)
67
+ # assert (-17).as_integer_ratio() == (-17, 1)
68
+ # assert (0).as_integer_ratio() == (0, 1)
69
+
64
70
# real/imag attributes
65
71
assert (1 ).real == 1
66
72
assert (1 ).imag == 0
Original file line number Diff line number Diff line change @@ -521,6 +521,14 @@ impl PyInt {
521
521
size_of :: < Self > ( ) + ( ( self . value . bits ( ) + 7 ) & !7 ) / 8
522
522
}
523
523
524
+ #[ pymethod( name = "as_integer_ratio" ) ]
525
+ fn as_integer_ratio ( & self , vm : & VirtualMachine ) -> PyResult {
526
+ Ok ( vm. ctx . new_tuple ( vec ! [
527
+ vm. ctx. new_bigint( & self . value) ,
528
+ vm. ctx. new_bigint( & BigInt :: one( ) ) ,
529
+ ] ) )
530
+ }
531
+
524
532
#[ pymethod]
525
533
fn bit_length ( & self ) -> usize {
526
534
self . value . bits ( )
You can’t perform that action at this time.
0 commit comments