Sha256: 9bb0584150e05a8a99e5fab366d801325a27291174d0dfda1c06a28308ec668b

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

#include "BigIntegerUtils.hh"
#include "BigUnsignedInABase.hh"

std::string bigUnsignedToString(const BigUnsigned &x) {
	return std::string(BigUnsignedInABase(x, 10));
}

std::string bigIntegerToString(const BigInteger &x) {
	return (x.getSign() == BigInteger::negative)
		? (std::string("-") + bigUnsignedToString(x.getMagnitude()))
		: (bigUnsignedToString(x.getMagnitude()));
}

BigUnsigned stringToBigUnsigned(const std::string &s) {
	return BigUnsigned(BigUnsignedInABase(s, 10));
}

BigInteger stringToBigInteger(const std::string &s) {
	// Recognize a sign followed by a BigUnsigned.
	return (s[0] == '-') ? BigInteger(stringToBigUnsigned(s.substr(1, s.length() - 1)), BigInteger::negative)
		: (s[0] == '+') ? BigInteger(stringToBigUnsigned(s.substr(1, s.length() - 1)))
		: BigInteger(stringToBigUnsigned(s));
}

std::ostream &operator <<(std::ostream &os, const BigUnsigned &x) {
	BigUnsignedInABase::Base base;
	long osFlags = os.flags();
	if (osFlags & os.dec)
		base = 10;
	else if (osFlags & os.hex) {
		base = 16;
		if (osFlags & os.showbase)
			os << "0x";
	} else if (osFlags & os.oct) {
		base = 8;
		if (osFlags & os.showbase)
			os << '0';
	} else
		throw "std::ostream << BigUnsigned: Could not determine the desired base from output-stream flags";
	std::string s = std::string(BigUnsignedInABase(x, base));
	os << s;
	return os;
}

std::ostream &operator <<(std::ostream &os, const BigInteger &x) {
	if (x.getSign() == BigInteger::negative)
		os << '-';
	os << x.getMagnitude();
	return os;
}

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
rhodes-7.6.0 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
rhodes-7.5.1 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
rhodes-7.4.1 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
zxing_cpp_mac_big_sur-0.1.1 ext/zxing/zxing-cpp/core/src/bigint/BigIntegerUtils.cc
rhodes-7.1.17 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
zxing_cpp_no_cmake-0.1.2 ext/zxing/zxing-cpp/core/src/bigint/BigIntegerUtils.cc
zxing_cpp_no_cmake-0.1.1 ext/zxing/zxing-cpp/core/src/bigint/BigIntegerUtils.cc
rhodes-6.2.0 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
rhodes-6.0.11 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
rhodes-5.5.18 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
rhodes-5.5.17 lib/commonAPI/barcode/ext/platform/qt/src/qzxing/zxing/bigint/BigIntegerUtils.cc
zxing_cpp-0.1.1 ext/zxing/zxing-cpp/core/src/bigint/BigIntegerUtils.cc
zxing_cpp-0.1.0 ext/zxing/zxing-cpp/core/src/bigint/BigIntegerUtils.cc