(self, other, precision=18)
| 82 | return Precise(integer_result, self.decimals + other.decimals) |
| 83 | |
| 84 | def div(self, other, precision=18): |
| 85 | distance = precision - self.decimals + other.decimals |
| 86 | if distance == 0: |
| 87 | numerator = self.integer |
| 88 | elif distance < 0: |
| 89 | exponent = self.base ** -distance |
| 90 | numerator = self.integer // exponent |
| 91 | else: |
| 92 | exponent = self.base ** distance |
| 93 | numerator = self.integer * exponent |
| 94 | result, mod = divmod(numerator, other.integer) |
| 95 | # python floors negative numbers down instead of truncating |
| 96 | # if mod is zero it will be floored to itself so we do not add one |
| 97 | result = result + 1 if result < 0 and mod else result |
| 98 | return Precise(result, precision) |
| 99 | |
| 100 | def add(self, other): |
| 101 | if self.decimals == other.decimals: |
no test coverage detected