|
@@ 777-799 (lines=23) @@
|
| 774 |
|
return Integer(args[0].bigint_value.mod(args[1].bigint_value)) |
| 775 |
|
|
| 776 |
|
|
| 777 |
|
class Div(Function): |
| 778 |
|
"""Integer division. Note this differs from Python's //, which is |
| 779 |
|
floor division. In Python: |
| 780 |
|
|
| 781 |
|
>>> 4.5 // 1.5 |
| 782 |
|
3.0 |
| 783 |
|
|
| 784 |
|
""" |
| 785 |
|
def call(self, args): |
| 786 |
|
check_args(u'div', args, 2, 2) |
| 787 |
|
|
| 788 |
|
for arg in args: |
| 789 |
|
if not isinstance(arg, Integer): |
| 790 |
|
return TrifleExceptionInstance( |
| 791 |
|
wrong_type, |
| 792 |
|
u"div requires integers, but got: %s." % arg.repr()) |
| 793 |
|
|
| 794 |
|
if args[1].bigint_value.eq(RBigInt.fromint(0)): |
| 795 |
|
return TrifleExceptionInstance( |
| 796 |
|
division_by_zero, |
| 797 |
|
u"Divided by zero: %s" % args[1].repr()) |
| 798 |
|
|
| 799 |
|
return Integer(args[0].bigint_value.floordiv(args[1].bigint_value)) |
| 800 |
|
|
| 801 |
|
|
| 802 |
|
class LessThan(Function): |
|
@@ 759-774 (lines=16) @@
|
| 756 |
|
|
| 757 |
|
|
| 758 |
|
# TODO: it would be nice to support floats too |
| 759 |
|
class Mod(Function): |
| 760 |
|
def call(self, args): |
| 761 |
|
check_args(u'mod', args, 2, 2) |
| 762 |
|
|
| 763 |
|
for arg in args: |
| 764 |
|
if not isinstance(arg, Integer): |
| 765 |
|
return TrifleExceptionInstance( |
| 766 |
|
wrong_type, |
| 767 |
|
u"mod requires integers, but got: %s." % arg.repr()) |
| 768 |
|
|
| 769 |
|
if args[1].bigint_value.eq(RBigInt.fromint(0)): |
| 770 |
|
return TrifleExceptionInstance( |
| 771 |
|
division_by_zero, |
| 772 |
|
u"Divided by zero: %s" % args[1].repr()) |
| 773 |
|
|
| 774 |
|
return Integer(args[0].bigint_value.mod(args[1].bigint_value)) |
| 775 |
|
|
| 776 |
|
|
| 777 |
|
class Div(Function): |