3 * Filename: BigIntegerIO.h
4 * Author: Matt McCutchen
8 #include "BigIntegerIO.h"
10 std::ostream& operator<<(std::ostream &os, BigUnsigned x) {
11 if (x.getLength() == 0)
17 * This buffer is filled with the decimal digits of x.
18 * sizeof(BigUnsigned::Blk) * x.getLength() is an upper bound on the
19 * number of bytes in x, and a byte takes at most 3 decimal
20 * digits, so this is a convenient upper bound.
22 char *buf = new char[sizeof(BigUnsigned::Blk) * x.getLength() * 3];
23 //std::cout << "bufferlength" << sizeof(BigUnsigned::Blk) * x.getLength() * 3<< std::endl;
24 int bufPos = 0; // first unfilled position
26 // While x is not zero...
28 //std::cout << "bufPos=" << bufPos << std::endl;
30 buf[bufPos] = char(int(x % ten) + '0');
37 // Now print the digits to os.
43 // Free the buffer and return the stream (as customary)
49 std::ostream& operator<<(std::ostream &os, BigInteger x) {
50 switch (x.getSign()) {
51 case BigInteger::positive:
54 case BigInteger::zero:
57 case BigInteger::negative:
58 os << '-' << BigUnsigned(x);