@@ -173,7 +173,7 @@ using parse_options = parse_options_t<char>;
173173// rust style `try!()` macro, or `?` operator
174174#define FASTFLOAT_TRY (x ) { if (!(x)) return false ; }
175175
176- #define FASTFLOAT_ENABLE_IF (...) typename std::enable_if<(__VA_ARGS__), int >::type = 0
176+ #define FASTFLOAT_ENABLE_IF (...) typename std::enable_if<(__VA_ARGS__), int >::type
177177
178178
179179namespace fast_float {
@@ -186,6 +186,20 @@ fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() {
186186#endif
187187}
188188
189+ template <typename T>
190+ fastfloat_really_inline constexpr bool is_supported_float_type () {
191+ return std::is_same<T, float >::value || std::is_same<T, double >::value;
192+ }
193+
194+ template <typename UC>
195+ fastfloat_really_inline constexpr bool is_supported_char_type () {
196+ return
197+ std::is_same<UC, char >::value ||
198+ std::is_same<UC, wchar_t >::value ||
199+ std::is_same<UC, char16_t >::value ||
200+ std::is_same<UC, char32_t >::value;
201+ }
202+
189203// Compares two ASCII strings in a case insensitive manner.
190204template <typename UC>
191205inline FASTFLOAT_CONSTEXPR14 bool
@@ -674,6 +688,69 @@ constexpr char32_t const * str_const_inf<char32_t>()
674688{
675689 return U" infinity" ;
676690}
691+
692+
693+ template <typename = void >
694+ struct int_luts {
695+ static constexpr uint8_t chdigit[] = {
696+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
697+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
698+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
699+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 255 , 255 , 255 , 255 , 255 , 255 ,
700+ 255 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ,
701+ 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 255 , 255 , 255 , 255 , 255 ,
702+ 255 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ,
703+ 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 255 , 255 , 255 , 255 , 255 ,
704+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
705+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
706+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
707+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
708+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
709+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
710+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
711+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255
712+ };
713+
714+ static constexpr size_t maxdigits_u64[] = {
715+ 64 , 41 , 32 , 28 , 25 , 23 , 22 , 21 ,
716+ 20 , 19 , 18 , 18 , 17 , 17 , 16 , 16 ,
717+ 16 , 16 , 15 , 15 , 15 , 15 , 14 , 14 ,
718+ 14 , 14 , 14 , 14 , 14 , 13 , 13 , 13 ,
719+ 13 , 13 , 13
720+ };
721+
722+ static constexpr uint64_t min_safe_u64[] = {
723+ 9223372036854775808ull , 12157665459056928801ull , 4611686018427387904 , 7450580596923828125 , 4738381338321616896 ,
724+ 3909821048582988049 , 9223372036854775808ull , 12157665459056928801ull , 10000000000000000000ull , 5559917313492231481 ,
725+ 2218611106740436992 , 8650415919381337933 , 2177953337809371136 , 6568408355712890625 , 1152921504606846976 ,
726+ 2862423051509815793 , 6746640616477458432 , 15181127029874798299ull , 1638400000000000000 , 3243919932521508681 ,
727+ 6221821273427820544 , 11592836324538749809ull , 876488338465357824 , 1490116119384765625 , 2481152873203736576 ,
728+ 4052555153018976267 , 6502111422497947648 , 10260628712958602189ull , 15943230000000000000ull , 787662783788549761 ,
729+ 1152921504606846976 , 1667889514952984961 , 2386420683693101056 , 3379220508056640625 , 4738381338321616896
730+ };
731+ };
732+
733+ template <typename T>
734+ constexpr uint8_t int_luts<T>::chdigit[];
735+
736+ template <typename T>
737+ constexpr size_t int_luts<T>::maxdigits_u64[];
738+
739+ template <typename T>
740+ constexpr uint64_t int_luts<T>::min_safe_u64[];
741+
742+ template <typename UC>
743+ fastfloat_really_inline
744+ constexpr uint8_t ch_to_digit (UC c) { return int_luts<>::chdigit[static_cast <unsigned char >(c)]; }
745+
746+ fastfloat_really_inline
747+ constexpr size_t max_digits_u64 (int base) { return int_luts<>::maxdigits_u64[base - 2 ]; }
748+
749+ // If a u64 is exactly max_digits_u64() in length, this is
750+ // the value below which it has definitely overflowed.
751+ fastfloat_really_inline
752+ constexpr uint64_t min_safe_u64 (int base) { return int_luts<>::min_safe_u64[base - 2 ]; }
753+
677754} // namespace fast_float
678755
679756#endif
0 commit comments