@@ -81,6 +81,9 @@ func IntNew(metatype *Type, args Tuple, kwargs StringDict) Object {
8181
8282// Arithmetic
8383
84+ // Errors
85+ var divisionByZero = ExceptionNewf (ZeroDivisionError , "division by zero" )
86+
8487// Convert an Object to an Int
8588//
8689// Retrurns ok as to whether the conversion worked or not
@@ -188,6 +191,9 @@ func (a Int) M__floordiv__(other Object) Object {
188191
189192func (a Int ) M__rfloordiv__ (other Object ) Object {
190193 if b , ok := convertToInt (other ); ok {
194+ if a == 0 {
195+ panic (divisionByZero )
196+ }
191197 return Int (b / a )
192198 }
193199 return NotImplemented
@@ -199,13 +205,19 @@ func (a Int) M__ifloordiv__(other Object) Object {
199205
200206func (a Int ) M__mod__ (other Object ) Object {
201207 if b , ok := convertToInt (other ); ok {
208+ if b == 0 {
209+ panic (divisionByZero )
210+ }
202211 return Int (a % b )
203212 }
204213 return NotImplemented
205214}
206215
207216func (a Int ) M__rmod__ (other Object ) Object {
208217 if b , ok := convertToInt (other ); ok {
218+ if a == 0 {
219+ panic (divisionByZero )
220+ }
209221 return Int (b % a )
210222 }
211223 return NotImplemented
@@ -217,13 +229,19 @@ func (a Int) M__imod__(other Object) Object {
217229
218230func (a Int ) M__divmod__ (other Object ) (Object , Object ) {
219231 if b , ok := convertToInt (other ); ok {
232+ if b == 0 {
233+ panic (divisionByZero )
234+ }
220235 return Int (a / b ), Int (a % b )
221236 }
222237 return NotImplemented , None
223238}
224239
225240func (a Int ) M__rdivmod__ (other Object ) (Object , Object ) {
226241 if b , ok := convertToInt (other ); ok {
242+ if a == 0 {
243+ panic (divisionByZero )
244+ }
227245 return Int (b / a ), Int (b % a )
228246 }
229247 return NotImplemented , None
0 commit comments