ext/include/iv/conversions.h in iv-phonic-0.0.9 vs ext/include/iv/conversions.h in iv-phonic-0.1.0

- old
+ new

@@ -6,20 +6,20 @@ #include <limits> #include <tr1/array> #include <tr1/cstdint> #include <tr1/cmath> #include "character.h" -#include "dtoa.h" #include "ustringpiece.h" #include "none.h" namespace iv { namespace core { namespace detail { template<typename T> class Conversions { public: static const double kNaN; + static const double kInf; static const int kMaxSignificantDigits = 772; static const std::string kInfinity; static const double DoubleToInt32_Two32; static const double DoubleToInt32_Two31; static const char* kHex; @@ -27,10 +27,13 @@ }; template<typename T> const double Conversions<T>::kNaN = std::numeric_limits<double>::quiet_NaN(); template<typename T> +const double Conversions<T>::kInf = std::numeric_limits<double>::infinity(); + +template<typename T> const std::string Conversions<T>::kInfinity = "Infinity"; template<typename T> const double Conversions<T>::DoubleToInt32_Two32 = 4294967296.0; @@ -344,11 +347,12 @@ if (it == last) { return Conversions::kNaN; } - double result = 0; + // TODO(Constellation) precision version + double result = 0.0; const Iter start = it; for (; it != last; ++it) { const int val = Radix36Value(*it); if (val != -1 && val < radix) { result = result * radix + val; @@ -367,9 +371,28 @@ inline double StringToIntegerWithRadix(const UStringPiece& range, int radix, bool strip_prefix) { return StringToIntegerWithRadix(range.begin(), range.end(), radix, strip_prefix); +} + +template<typename Iter> +inline double ParseIntegerOverflow(Iter it, Iter last, int radix) { + double number = 0.0; + double multiplier = 1.0; + for (--it, --last; last != it; --last) { + if (multiplier == Conversions::kInf) { + if (*last != '0') { + number = Conversions::kInf; + break; + } + } else { + const int digit = Radix36Value(*last); + number += digit * multiplier; + } + multiplier *= radix; + } + return number; } inline std::size_t StringToHash(const UStringPiece& x) { std::size_t len = x.size(); std::size_t step = (len >> 5) + 1;