31 static const unsigned int DOUBLE_EXPONENT_WIDTH = 11;
32 static const unsigned int DOUBLE_MANTISSA_WIDTH = 52;
33 static const unsigned int FLOAT_EXPONENT_WIDTH = 8;
34 static const unsigned int FLOAT_MANTISSA_WIDTH = 23;
35 static const unsigned int HEX_RADIX = 16;
36 static const unsigned int MAX_SIGNIFICANT_LENGTH = 15;
38 static const std::string HEX_SIGNIFICANT;
39 static const std::string BINARY_EXPONENT;
40 static const std::string FLOAT_TYPE_SUFFIX;
41 static const std::string HEX_PATTERN;
50 long long EXPONENT_BASE;
51 long long MAX_EXPONENT;
52 long long MIN_EXPONENT;
53 long long MANTISSA_MASK;
57 std::string abandonedNumber;
78 long long parse(
const std::string& hexString);
86 void parseHexSign(
const std::string& signStr) {
87 this->sign = signStr.compare(
"-") == 0 ? 1 : 0;
94 void parseExponent(
const std::string& exponentStr);
100 void parseMantissa(
const std::string& significantStr);
103 exponent = MAX_EXPONENT;
117 void checkedAddExponent(
long long offset);
119 void processNormalNumber();
120 void processSubNormalNumber();
121 int countBitsLength(
long long value);
126 void fitMantissaInDesiredWidth(
int desiredWidth);
131 void discardTrailingBits(
long long num);
143 std::string getNormalizedSignificand(
const std::string& strIntegerPart,
const std::string& strDecimalPart);
151 int getOffset(
const std::string& strIntegerPart,
const std::string& strDecimalPart);
178 static std::string* getSegmentsFromHexString(
const std::string& hexString);
180 std::string& replaceFirst(std::string& target,
const std::string& find,
const std::string& replace) {
182 std::string::size_type pos = std::string::npos;
184 if ((pos = target.find_first_of(find, 0)) != std::string::npos) {
185 return target.replace(pos, find.length(), replace);
191 std::string& replaceAll(std::string& target,
const std::string& find,
const std::string& replace) {
193 std::string::size_type pos = std::string::npos;
194 while ((pos = target.find(find)) != std::string::npos) {
195 target.replace(pos, find.length(), replace);