@@ -138,6 +138,14 @@ fn inner_pow(int1: &PyInt, int2: &PyInt, vm: &VirtualMachine) -> PyResult {
138138 Ok ( result)
139139}
140140
141+ fn inner_mod ( int1 : & PyInt , int2 : & PyInt , vm : & VirtualMachine ) -> PyResult {
142+ if int2. value != BigInt :: zero ( ) {
143+ Ok ( vm. ctx . new_int ( & int1. value % & int2. value ) )
144+ } else {
145+ Err ( vm. new_zero_division_error ( "integer modulo by zero" . to_string ( ) ) )
146+ }
147+ }
148+
141149#[ pyimpl]
142150impl PyInt {
143151 #[ pymethod( name = "__eq__" ) ]
@@ -369,12 +377,18 @@ impl PyInt {
369377 #[ pymethod( name = "__mod__" ) ]
370378 fn mod_ ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
371379 if objtype:: isinstance ( & other, & vm. ctx . int_type ( ) ) {
372- let v2 = get_value ( & other) ;
373- if * v2 != BigInt :: zero ( ) {
374- Ok ( vm. ctx . new_int ( ( & self . value ) % v2) )
375- } else {
376- Err ( vm. new_zero_division_error ( "integer modulo by zero" . to_string ( ) ) )
377- }
380+ let other = other. payload :: < PyInt > ( ) . unwrap ( ) ;
381+ inner_mod ( self , & other, vm)
382+ } else {
383+ Ok ( vm. ctx . not_implemented ( ) )
384+ }
385+ }
386+
387+ #[ pymethod( name = "__rmod__" ) ]
388+ fn rmod ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
389+ if objtype:: isinstance ( & other, & vm. ctx . int_type ( ) ) {
390+ let other = other. payload :: < PyInt > ( ) . unwrap ( ) ;
391+ inner_mod ( & other, self , vm)
378392 } else {
379393 Ok ( vm. ctx . not_implemented ( ) )
380394 }
0 commit comments