1e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// Copyright 2014 PDFium Authors. All rights reserved. 2e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// Use of this source code is governed by a BSD-style license that can be 3e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// found in the LICENSE file. 4e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 5e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// Original code by Matt McCutchen, see the LICENSE file. 6e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 7e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#ifndef BIGINTEGER_H 8e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define BIGINTEGER_H 9e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 10e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include "BigUnsigned.hh" 11e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 12e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* A BigInteger object represents a signed integer of size limited only by 13e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * available memory. BigUnsigneds support most mathematical operators and can 14e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * be converted to and from most primitive integer types. 15e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 16e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * A BigInteger is just an aggregate of a BigUnsigned and a sign. (It is no 17e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * longer derived from BigUnsigned because that led to harmful implicit 18e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * conversions.) */ 19e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovclass BigInteger { 20e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 21e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovpublic: 22e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov typedef BigUnsigned::Blk Blk; 23e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov typedef BigUnsigned::Index Index; 24e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov typedef BigUnsigned::CmpRes CmpRes; 25e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov static const CmpRes 26e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov less = BigUnsigned::less , 27e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov equal = BigUnsigned::equal , 28e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov greater = BigUnsigned::greater; 29e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Enumeration for the sign of a BigInteger. 30e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov enum Sign { negative = -1, zero = 0, positive = 1 }; 31e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 32e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovprotected: 33e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov Sign sign; 34e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigUnsigned mag; 35e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 36e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovpublic: 37e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Constructs zero. 38e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger() : sign(zero), mag() {} 39e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 40e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Copy constructor 41e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(const BigInteger &x) : sign(x.sign), mag(x.mag) {}; 42e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 43e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Assignment operator 44e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator=(const BigInteger &x); 45e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 46e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Constructor that copies from a given array of blocks with a sign. 47e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(const Blk *b, Index blen, Sign s); 48e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 49e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Nonnegative constructor that copies from a given array of blocks. 50e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(const Blk *b, Index blen) : mag(b, blen) { 51e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov sign = mag.isZero() ? zero : positive; 52e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov } 53e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 54e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Constructor from a BigUnsigned and a sign 55e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(const BigUnsigned &x, Sign s); 56e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 57e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Nonnegative constructor from a BigUnsigned 58e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(const BigUnsigned &x) : mag(x) { 59e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov sign = mag.isZero() ? zero : positive; 60e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov } 61e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 62e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Constructors from primitive integer types 63e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(unsigned long x); 64e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger( long x); 65e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(unsigned int x); 66e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger( int x); 67e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger(unsigned short x); 68e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger( short x); 69e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 70e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Converters to primitive integer types 71e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * The implicit conversion operators caused trouble, so these are now 72e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * named. */ 73e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov unsigned long toUnsignedLong () const; 74e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov long toLong () const; 75e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov unsigned int toUnsignedInt () const; 76e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov int toInt () const; 77e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov unsigned short toUnsignedShort() const; 78e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov short toShort () const; 79e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovprotected: 80e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Helper 81e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov template <class X> X convertToUnsignedPrimitive() const; 82e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov template <class X, class UX> X convertToSignedPrimitive() const; 83e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovpublic: 84e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 85e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // ACCESSORS 86e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov Sign getSign() const { return sign; } 87e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* The client can't do any harm by holding a read-only reference to the 88e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * magnitude. */ 89e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov const BigUnsigned &getMagnitude() const { return mag; } 90e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 91e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Some accessors that go through to the magnitude 92e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov Index getLength() const { return mag.getLength(); } 93e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov Index getCapacity() const { return mag.getCapacity(); } 94e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov Blk getBlock(Index i) const { return mag.getBlock(i); } 95e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov bool isZero() const { return sign == zero; } // A bit special 96e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 97e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // COMPARISONS 98e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 99e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Compares this to x like Perl's <=> 100e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov CmpRes compareTo(const BigInteger &x) const; 101e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 102e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Ordinary comparison operators 103e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov bool operator ==(const BigInteger &x) const { 104e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov return sign == x.sign && mag == x.mag; 105e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov } 106e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov bool operator !=(const BigInteger &x) const { return !operator ==(x); }; 107e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov bool operator < (const BigInteger &x) const { return compareTo(x) == less ; } 108e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov bool operator <=(const BigInteger &x) const { return compareTo(x) != greater; } 109e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov bool operator >=(const BigInteger &x) const { return compareTo(x) != less ; } 110e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov bool operator > (const BigInteger &x) const { return compareTo(x) == greater; } 111e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 112e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // OPERATORS -- See the discussion in BigUnsigned.hh. 113e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void add (const BigInteger &a, const BigInteger &b); 114e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void subtract(const BigInteger &a, const BigInteger &b); 115e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void multiply(const BigInteger &a, const BigInteger &b); 116e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* See the comment on BigUnsigned::divideWithRemainder. Semantics 117e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * differ from those of primitive integers when negatives and/or zeros 118e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * are involved. */ 119e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void divideWithRemainder(const BigInteger &b, BigInteger &q); 120e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void negate(const BigInteger &a); 121e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 122e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Bitwise operators are not provided for BigIntegers. Use 123e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * getMagnitude to get the magnitude and operate on that instead. */ 124e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 125e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger operator +(const BigInteger &x) const; 126e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger operator -(const BigInteger &x) const; 127e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger operator *(const BigInteger &x) const; 128e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger operator /(const BigInteger &x) const; 129e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger operator %(const BigInteger &x) const; 130e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger operator -() const; 131e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 132e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator +=(const BigInteger &x); 133e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator -=(const BigInteger &x); 134e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator *=(const BigInteger &x); 135e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator /=(const BigInteger &x); 136e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator %=(const BigInteger &x); 137e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void flipSign(); 138e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 139e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // INCREMENT/DECREMENT OPERATORS 140e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator ++( ); 141e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator ++(int); 142e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator --( ); 143e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov void operator --(int); 144e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov}; 145e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 146e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// NORMAL OPERATORS 147e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* These create an object to hold the result and invoke 148e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * the appropriate put-here operation on it, passing 149e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * this and x. The new object is then returned. */ 150e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline BigInteger BigInteger::operator +(const BigInteger &x) const { 151e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger ans; 152e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov ans.add(*this, x); 153e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov return ans; 154e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 155e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline BigInteger BigInteger::operator -(const BigInteger &x) const { 156e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger ans; 157e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov ans.subtract(*this, x); 158e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov return ans; 159e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 160e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline BigInteger BigInteger::operator *(const BigInteger &x) const { 161e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger ans; 162e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov ans.multiply(*this, x); 163e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov return ans; 164e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 165e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline BigInteger BigInteger::operator /(const BigInteger &x) const { 166e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov if (x.isZero()) 167e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov abort(); 168e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger q, r; 169e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov r = *this; 170e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov r.divideWithRemainder(x, q); 171e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov return q; 172e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 173e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline BigInteger BigInteger::operator %(const BigInteger &x) const { 174e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov if (x.isZero()) 175e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov abort(); 176e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger q, r; 177e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov r = *this; 178e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov r.divideWithRemainder(x, q); 179e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov return r; 180e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 181e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline BigInteger BigInteger::operator -() const { 182e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger ans; 183e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov ans.negate(*this); 184e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov return ans; 185e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 186e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 187e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* 188e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * ASSIGNMENT OPERATORS 189e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 190e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * Now the responsibility for making a temporary copy if necessary 191e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * belongs to the put-here operations. See Assignment Operators in 192e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * BigUnsigned.hh. 193e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 194e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline void BigInteger::operator +=(const BigInteger &x) { 195e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov add(*this, x); 196e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 197e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline void BigInteger::operator -=(const BigInteger &x) { 198e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov subtract(*this, x); 199e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 200e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline void BigInteger::operator *=(const BigInteger &x) { 201e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov multiply(*this, x); 202e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 203e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline void BigInteger::operator /=(const BigInteger &x) { 204e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov if (x.isZero()) 205e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov abort(); 206e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* The following technique is slightly faster than copying *this first 207e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * when x is large. */ 208e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger q; 209e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov divideWithRemainder(x, q); 210e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // *this contains the remainder, but we overwrite it with the quotient. 211e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov *this = q; 212e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 213e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline void BigInteger::operator %=(const BigInteger &x) { 214e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov if (x.isZero()) 215e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov abort(); 216e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov BigInteger q; 217e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov // Mods *this by x. Don't care about quotient left in q. 218e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov divideWithRemainder(x, q); 219e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 220e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// This one is trivial 221e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovinline void BigInteger::flipSign() { 222e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov sign = Sign(-sign); 223e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 224e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 225e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 226