1 #include "BigIntegerUtils.hh"
2 #include "BigUnsignedInABase.hh"
4 std::string
bigUnsignedToString(const BigUnsigned
&x
) {
5 return std::string(BigUnsignedInABase(x
, 10));
8 std::string
bigIntegerToString(const BigInteger
&x
) {
9 return (x
.getSign() == BigInteger::negative
)
10 ? (std::string("-") + bigUnsignedToString(x
.getMagnitude()))
11 : (bigUnsignedToString(x
.getMagnitude()));
14 BigUnsigned
stringToBigUnsigned(const std::string
&s
) {
15 return BigUnsigned(BigUnsignedInABase(s
, 10));
18 BigInteger
stringToBigInteger(const std::string
&s
) {
19 // Recognize a sign followed by a BigUnsigned.
20 return (s
[0] == '-') ? BigInteger(stringToBigUnsigned(s
.substr(1, s
.length() - 1)), BigInteger::negative
)
21 : (s
[0] == '+') ? BigInteger(stringToBigUnsigned(s
.substr(1, s
.length() - 1)))
22 : BigInteger(stringToBigUnsigned(s
));
25 std::ostream
&operator <<(std::ostream
&os
, const BigUnsigned
&x
) {
26 BigUnsignedInABase::Base base
;
27 long osFlags
= os
.flags();
30 else if (osFlags
& os
.hex
) {
32 if (osFlags
& os
.showbase
)
34 } else if (osFlags
& os
.oct
) {
36 if (osFlags
& os
.showbase
)
39 throw "std::ostream << BigUnsigned: Could not determine the desired base from output-stream flags";
40 std::string s
= std::string(BigUnsignedInABase(x
, base
));
45 std::ostream
&operator <<(std::ostream
&os
, const BigInteger
&x
) {
46 if (x
.getSign() == BigInteger::negative
)
48 os
<< x
.getMagnitude();