| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code by Matt McCutchen, see the LICENSE file. | 5 // Original code by Matt McCutchen, see the LICENSE file. |
| 6 | 6 |
| 7 #ifndef BIGINTEGER_H | 7 #ifndef BIGINTEGER_H |
| 8 #define BIGINTEGER_H | 8 #define BIGINTEGER_H |
| 9 | 9 |
| 10 #include "BigUnsigned.hh" | 10 #include "BigUnsigned.hh" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 ans.subtract(*this, x); | 157 ans.subtract(*this, x); |
| 158 return ans; | 158 return ans; |
| 159 } | 159 } |
| 160 inline BigInteger BigInteger::operator *(const BigInteger &x) const { | 160 inline BigInteger BigInteger::operator *(const BigInteger &x) const { |
| 161 BigInteger ans; | 161 BigInteger ans; |
| 162 ans.multiply(*this, x); | 162 ans.multiply(*this, x); |
| 163 return ans; | 163 return ans; |
| 164 } | 164 } |
| 165 inline BigInteger BigInteger::operator /(const BigInteger &x) const { | 165 inline BigInteger BigInteger::operator /(const BigInteger &x) const { |
| 166 if (x.isZero()) | 166 if (x.isZero()) |
| 167 #ifdef FOXIT_CHROME_BUILD | |
| 168 abort(); | 167 abort(); |
| 169 #else | |
| 170 throw "BigInteger::operator /: division by zero"; | |
| 171 #endif | |
| 172 BigInteger q, r; | 168 BigInteger q, r; |
| 173 r = *this; | 169 r = *this; |
| 174 r.divideWithRemainder(x, q); | 170 r.divideWithRemainder(x, q); |
| 175 return q; | 171 return q; |
| 176 } | 172 } |
| 177 inline BigInteger BigInteger::operator %(const BigInteger &x) const { | 173 inline BigInteger BigInteger::operator %(const BigInteger &x) const { |
| 178 if (x.isZero()) | 174 if (x.isZero()) |
| 179 #ifdef FOXIT_CHROME_BUILD | |
| 180 abort(); | 175 abort(); |
| 181 #else | |
| 182 throw "BigInteger::operator %: division by zero"; | |
| 183 #endif | |
| 184 BigInteger q, r; | 176 BigInteger q, r; |
| 185 r = *this; | 177 r = *this; |
| 186 r.divideWithRemainder(x, q); | 178 r.divideWithRemainder(x, q); |
| 187 return r; | 179 return r; |
| 188 } | 180 } |
| 189 inline BigInteger BigInteger::operator -() const { | 181 inline BigInteger BigInteger::operator -() const { |
| 190 BigInteger ans; | 182 BigInteger ans; |
| 191 ans.negate(*this); | 183 ans.negate(*this); |
| 192 return ans; | 184 return ans; |
| 193 } | 185 } |
| 194 | 186 |
| 195 /* | 187 /* |
| 196 * ASSIGNMENT OPERATORS | 188 * ASSIGNMENT OPERATORS |
| 197 * | 189 * |
| 198 * Now the responsibility for making a temporary copy if necessary | 190 * Now the responsibility for making a temporary copy if necessary |
| 199 * belongs to the put-here operations. See Assignment Operators in | 191 * belongs to the put-here operations. See Assignment Operators in |
| 200 * BigUnsigned.hh. | 192 * BigUnsigned.hh. |
| 201 */ | 193 */ |
| 202 inline void BigInteger::operator +=(const BigInteger &x) { | 194 inline void BigInteger::operator +=(const BigInteger &x) { |
| 203 add(*this, x); | 195 add(*this, x); |
| 204 } | 196 } |
| 205 inline void BigInteger::operator -=(const BigInteger &x) { | 197 inline void BigInteger::operator -=(const BigInteger &x) { |
| 206 subtract(*this, x); | 198 subtract(*this, x); |
| 207 } | 199 } |
| 208 inline void BigInteger::operator *=(const BigInteger &x) { | 200 inline void BigInteger::operator *=(const BigInteger &x) { |
| 209 multiply(*this, x); | 201 multiply(*this, x); |
| 210 } | 202 } |
| 211 inline void BigInteger::operator /=(const BigInteger &x) { | 203 inline void BigInteger::operator /=(const BigInteger &x) { |
| 212 if (x.isZero()) | 204 if (x.isZero()) |
| 213 #ifdef FOXIT_CHROME_BUILD | |
| 214 abort(); | 205 abort(); |
| 215 #else | |
| 216 throw "BigInteger::operator /=: division by zero"; | |
| 217 #endif | |
| 218 /* The following technique is slightly faster than copying *this first | 206 /* The following technique is slightly faster than copying *this first |
| 219 * when x is large. */ | 207 * when x is large. */ |
| 220 BigInteger q; | 208 BigInteger q; |
| 221 divideWithRemainder(x, q); | 209 divideWithRemainder(x, q); |
| 222 // *this contains the remainder, but we overwrite it with the quotient. | 210 // *this contains the remainder, but we overwrite it with the quotient. |
| 223 *this = q; | 211 *this = q; |
| 224 } | 212 } |
| 225 inline void BigInteger::operator %=(const BigInteger &x) { | 213 inline void BigInteger::operator %=(const BigInteger &x) { |
| 226 if (x.isZero()) | 214 if (x.isZero()) |
| 227 #ifdef FOXIT_CHROME_BUILD | |
| 228 abort(); | 215 abort(); |
| 229 #else | |
| 230 throw "BigInteger::operator %=: division by zero"; | |
| 231 #endif | |
| 232 BigInteger q; | 216 BigInteger q; |
| 233 // Mods *this by x. Don't care about quotient left in q. | 217 // Mods *this by x. Don't care about quotient left in q. |
| 234 divideWithRemainder(x, q); | 218 divideWithRemainder(x, q); |
| 235 } | 219 } |
| 236 // This one is trivial | 220 // This one is trivial |
| 237 inline void BigInteger::flipSign() { | 221 inline void BigInteger::flipSign() { |
| 238 sign = Sign(-sign); | 222 sign = Sign(-sign); |
| 239 } | 223 } |
| 240 | 224 |
| 241 #endif | 225 #endif |
| OLD | NEW |