@@ -199,7 +199,7 @@ struct BigInt(Absable, IntableRaising, Representable, Stringable, Writable):
199199 return Self(BigUInt(list_of_words^ ), sign)
200200
201201 @ staticmethod
202- fn from_int (value : Int) raises -> Self:
202+ fn from_int (value : Int) -> Self:
203203 """ Creates a BigInt from an integer."""
204204 if value == 0 :
205205 return Self()
@@ -421,22 +421,46 @@ struct BigInt(Absable, IntableRaising, Representable, Stringable, Writable):
421421 fn __add__ (self , other : Self) raises -> Self:
422422 return decimojo.bigint.arithmetics.add(self , other)
423423
424+ @always_inline
425+ fn __add__ (self , other : Int) raises -> Self:
426+ return decimojo.bigint.arithmetics.add(self , Self.from_int(other))
427+
424428 @always_inline
425429 fn __sub__ (self , other : Self) raises -> Self:
426430 return decimojo.bigint.arithmetics.subtract(self , other)
427431
432+ @always_inline
433+ fn __sub__ (self , other : Int) raises -> Self:
434+ return decimojo.bigint.arithmetics.subtract(self , Self.from_int(other))
435+
428436 @always_inline
429437 fn __mul__ (self , other : Self) raises -> Self:
430438 return decimojo.bigint.arithmetics.multiply(self , other)
431439
440+ @always_inline
441+ fn __mul__ (self , other : Int) raises -> Self:
442+ return decimojo.bigint.arithmetics.multiply(self , Self.from_int(other))
443+
432444 @always_inline
433445 fn __floordiv__ (self , other : Self) raises -> Self:
434446 return decimojo.bigint.arithmetics.floor_divide(self , other)
435447
448+ @always_inline
449+ fn __floordiv__ (self , other : Int) raises -> Self:
450+ return decimojo.bigint.arithmetics.floor_divide(
451+ self , Self.from_int(other)
452+ )
453+
436454 @always_inline
437455 fn __mod__ (self , other : Self) raises -> Self:
438456 return decimojo.bigint.arithmetics.floor_modulo(self , other)
439457
458+ @always_inline
459+ fn __mod__ (self , other : Int) raises -> Self:
460+ return decimojo.bigint.arithmetics.floor_modulo(
461+ self , Self.from_int(other)
462+ )
463+
440464 @always_inline
441465 fn __pow__ (self , exponent : Self) raises -> Self:
442466 return self .power(exponent)
@@ -445,6 +469,40 @@ struct BigInt(Absable, IntableRaising, Representable, Stringable, Writable):
445469 fn __pow__ (self , exponent : Int) raises -> Self:
446470 return self .power(exponent)
447471
472+ # ===------------------------------------------------------------------=== #
473+ # Basic binary right-side arithmetic operation dunders
474+ # These methods are called to implement the binary arithmetic operations
475+ # (+, -, *, @, /, //, %, divmod(), pow(), **, <<, >>, &, ^, |)
476+ # ===------------------------------------------------------------------=== #
477+
478+ @always_inline
479+ fn __radd__ (self , other : Int) raises -> Self:
480+ return decimojo.bigint.arithmetics.add(self , Self.from_int(other))
481+
482+ @always_inline
483+ fn __rsub__ (self , other : Int) raises -> Self:
484+ return decimojo.bigint.arithmetics.subtract(Self.from_int(other), self )
485+
486+ @always_inline
487+ fn __rmul__ (self , other : Int) raises -> Self:
488+ return decimojo.bigint.arithmetics.multiply(self , Self.from_int(other))
489+
490+ @always_inline
491+ fn __rfloordiv__ (self , other : Int) raises -> Self:
492+ return decimojo.bigint.arithmetics.floor_divide(
493+ Self.from_int(other), self
494+ )
495+
496+ @always_inline
497+ fn __rmod__ (self , other : Int) raises -> Self:
498+ return decimojo.bigint.arithmetics.floor_modulo(
499+ Self.from_int(other), self
500+ )
501+
502+ @always_inline
503+ fn __rpow__ (self , base : Int) raises -> Self:
504+ return Self(base).power(self )
505+
448506 # ===------------------------------------------------------------------=== #
449507 # Basic binary augmented arithmetic assignments dunders
450508 # These methods are called to implement the binary augmented arithmetic
@@ -456,22 +514,46 @@ struct BigInt(Absable, IntableRaising, Representable, Stringable, Writable):
456514 fn __iadd__ (mut self , other : Self) raises :
457515 self = decimojo.bigint.arithmetics.add(self , other)
458516
517+ @always_inline
518+ fn __iadd__ (mut self , other : Int) raises :
519+ self = decimojo.bigint.arithmetics.add(self , Self.from_int(other))
520+
459521 @always_inline
460522 fn __isub__ (mut self , other : Self) raises :
461523 self = decimojo.bigint.arithmetics.subtract(self , other)
462524
525+ @always_inline
526+ fn __isub__ (mut self , other : Int) raises :
527+ self = decimojo.bigint.arithmetics.subtract(self , Self.from_int(other))
528+
463529 @always_inline
464530 fn __imul__ (mut self , other : Self) raises :
465531 self = decimojo.bigint.arithmetics.multiply(self , other)
466532
533+ @always_inline
534+ fn __imul__ (mut self , other : Int) raises :
535+ self = decimojo.bigint.arithmetics.multiply(self , Self.from_int(other))
536+
467537 @always_inline
468538 fn __ifloordiv__ (mut self , other : Self) raises :
469539 self = decimojo.bigint.arithmetics.floor_divide(self , other)
470540
541+ @always_inline
542+ fn __ifloordiv__ (mut self , other : Int) raises :
543+ self = decimojo.bigint.arithmetics.floor_divide(
544+ self , Self.from_int(other)
545+ )
546+
471547 @always_inline
472548 fn __imod__ (mut self , other : Self) raises :
473549 self = decimojo.bigint.arithmetics.floor_modulo(self , other)
474550
551+ @always_inline
552+ fn __imod__ (mut self , other : Int) raises :
553+ self = decimojo.bigint.arithmetics.floor_modulo(
554+ self , Self.from_int(other)
555+ )
556+
475557 # ===------------------------------------------------------------------=== #
476558 # Basic binary comparison operation dunders
477559 # __gt__, __ge__, __lt__, __le__, __eq__, __ne__
@@ -482,31 +564,63 @@ struct BigInt(Absable, IntableRaising, Representable, Stringable, Writable):
482564 """ Returns True if self > other."""
483565 return decimojo.bigint.comparison.greater(self , other)
484566
567+ @always_inline
568+ fn __gt__ (self , other : Int) -> Bool:
569+ """ Returns True if self > other."""
570+ return decimojo.bigint.comparison.greater(self , Self.from_int(other))
571+
485572 @always_inline
486573 fn __ge__ (self , other : Self) -> Bool:
487574 """ Returns True if self >= other."""
488575 return decimojo.bigint.comparison.greater_equal(self , other)
489576
577+ @always_inline
578+ fn __ge__ (self , other : Int) -> Bool:
579+ """ Returns True if self >= other."""
580+ return decimojo.bigint.comparison.greater_equal(
581+ self , Self.from_int(other)
582+ )
583+
490584 @always_inline
491585 fn __lt__ (self , other : Self) -> Bool:
492586 """ Returns True if self < other."""
493587 return decimojo.bigint.comparison.less(self , other)
494588
589+ @always_inline
590+ fn __lt__ (self , other : Int) -> Bool:
591+ """ Returns True if self < other."""
592+ return decimojo.bigint.comparison.less(self , Self.from_int(other))
593+
495594 @always_inline
496595 fn __le__ (self , other : Self) -> Bool:
497596 """ Returns True if self <= other."""
498597 return decimojo.bigint.comparison.less_equal(self , other)
499598
599+ @always_inline
600+ fn __le__ (self , other : Int) -> Bool:
601+ """ Returns True if self <= other."""
602+ return decimojo.bigint.comparison.less_equal(self , Self.from_int(other))
603+
500604 @always_inline
501605 fn __eq__ (self , other : Self) -> Bool:
502606 """ Returns True if self == other."""
503607 return decimojo.bigint.comparison.equal(self , other)
504608
609+ @always_inline
610+ fn __eq__ (self , other : Int) -> Bool:
611+ """ Returns True if self == other."""
612+ return decimojo.bigint.comparison.equal(self , Self.from_int(other))
613+
505614 @always_inline
506615 fn __ne__ (self , other : Self) -> Bool:
507616 """ Returns True if self != other."""
508617 return decimojo.bigint.comparison.not_equal(self , other)
509618
619+ @always_inline
620+ fn __ne__ (self , other : Int) -> Bool:
621+ """ Returns True if self != other."""
622+ return decimojo.bigint.comparison.not_equal(self , Self.from_int(other))
623+
510624 # ===------------------------------------------------------------------=== #
511625 # Mathematical methods that do not implement a trait (not a dunder)
512626 # ===------------------------------------------------------------------=== #
0 commit comments