diff --git a/include/date/date.h b/include/date/date.h index 98c8b0e..1ad5424 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -45,9 +45,7 @@ #include #include #include -#if !(__cplusplus >= 201402) -# include -#endif +#include #include #include #include @@ -6169,9 +6167,16 @@ long double read_long_double(std::basic_istream& is, unsigned m = 1, unsigned M = 10) { unsigned count = 0; + unsigned fcount = 0; + unsigned long long i = 0; + unsigned long long f = 0; + bool parsing_fraction = false; +#if ONLY_C_LOCALE + typename Traits::int_type decimal_point = '.'; +#else auto decimal_point = Traits::to_int_type( std::use_facet>(is.getloc()).decimal_point()); - std::string buf; +#endif while (true) { auto ic = is.peek(); @@ -6179,18 +6184,25 @@ read_long_double(std::basic_istream& is, unsigned m = 1, unsigned break; if (Traits::eq_int_type(ic, decimal_point)) { - buf += '.'; decimal_point = Traits::eof(); - is.get(); + parsing_fraction = true; } else { auto c = static_cast(Traits::to_char_type(ic)); if (!('0' <= c && c <= '9')) break; - buf += c; - (void)is.get(); + if (!parsing_fraction) + { + i = 10*i + static_cast(c - '0'); + } + else + { + f = 10*f + static_cast(c - '0'); + ++fcount; + } } + (void)is.get(); if (++count == M) break; } @@ -6199,7 +6211,7 @@ read_long_double(std::basic_istream& is, unsigned m = 1, unsigned is.setstate(std::ios::failbit); return 0; } - return std::stold(buf); + return i + f/std::pow(10.L, fcount); } struct rs