FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fast_float.h
1// fast_float by Daniel Lemire
2// fast_float by João Paulo Magalhaes
3//
4//
5// with contributions from Eugene Golushkov
6// with contributions from Maksim Kita
7// with contributions from Marcin Wojdyr
8// with contributions from Neal Richardson
9// with contributions from Tim Paine
10// with contributions from Fabio Pellacini
11// with contributions from Lénárd Szolnoki
12// with contributions from Jan Pharago
13// with contributions from Maya Warrier
14// with contributions from Taha Khokhar
15// with contributions from Anders Dalvander
16//
17//
18// Licensed under the Apache License, Version 2.0, or the
19// MIT License or the Boost License. This file may not be copied,
20// modified, or distributed except according to those terms.
21//
22// MIT License Notice
23//
24// MIT License
25//
26// Copyright (c) 2021 The fast_float authors
27//
28// Permission is hereby granted, free of charge, to any
29// person obtaining a copy of this software and associated
30// documentation files (the "Software"), to deal in the
31// Software without restriction, including without
32// limitation the rights to use, copy, modify, merge,
33// publish, distribute, sublicense, and/or sell copies of
34// the Software, and to permit persons to whom the Software
35// is furnished to do so, subject to the following
36// conditions:
37//
38// The above copyright notice and this permission notice
39// shall be included in all copies or substantial portions
40// of the Software.
41//
42// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
43// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
44// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
45// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
46// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
48// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
49// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
50// DEALINGS IN THE SOFTWARE.
51//
52// Apache License (Version 2.0) Notice
53//
54// Copyright 2021 The fast_float authors
55// Licensed under the Apache License, Version 2.0 (the "License");
56// you may not use this file except in compliance with the License.
57// You may obtain a copy of the License at
58//
59// http://www.apache.org/licenses/LICENSE-2.0
60//
61// Unless required by applicable law or agreed to in writing, software
62// distributed under the License is distributed on an "AS IS" BASIS,
63// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
64// See the License for the specific language governing permissions and
65//
66// BOOST License Notice
67//
68// Boost Software License - Version 1.0 - August 17th, 2003
69//
70// Permission is hereby granted, free of charge, to any person or organization
71// obtaining a copy of the software and accompanying documentation covered by
72// this license (the "Software") to use, reproduce, display, distribute,
73// execute, and transmit the Software, and to prepare derivative works of the
74// Software, and to permit third-parties to whom the Software is furnished to
75// do so, all subject to the following:
76//
77// The copyright notices in the Software and this entire statement, including
78// the above license grant, this restriction and the following disclaimer,
79// must be included in all copies of the Software, in whole or in part, and
80// all derivative works of the Software, unless such copies or derivative
81// works are solely in the form of machine-executable object code generated by
82// a source language processor.
83//
84// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
87// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
88// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
89// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
90// DEALINGS IN THE SOFTWARE.
91//
92
93#ifndef FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H
94#define FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H
95
96#ifdef __has_include
97#if __has_include(<version>)
98#include <version>
99#endif
100#endif
101
102// Testing for https://wg21.link/N3652, adopted in C++14
103#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
104#define FASTFLOAT_CONSTEXPR14 constexpr
105#else
106#define FASTFLOAT_CONSTEXPR14
107#endif
108
109#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L
110#define FASTFLOAT_HAS_BIT_CAST 1
111#else
112#define FASTFLOAT_HAS_BIT_CAST 0
113#endif
114
115#if defined(__cpp_lib_is_constant_evaluated) && \
116 __cpp_lib_is_constant_evaluated >= 201811L
117#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 1
118#else
119#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0
120#endif
121
122#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
123#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
124#else
125#define FASTFLOAT_IF_CONSTEXPR17(x) if (x)
126#endif
127
128// Testing for relevant C++20 constexpr library features
129#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST && \
130 defined(__cpp_lib_constexpr_algorithms) && \
131 __cpp_lib_constexpr_algorithms >= 201806L /*For std::copy and std::fill*/
132#define FASTFLOAT_CONSTEXPR20 constexpr
133#define FASTFLOAT_IS_CONSTEXPR 1
134#else
135#define FASTFLOAT_CONSTEXPR20
136#define FASTFLOAT_IS_CONSTEXPR 0
137#endif
138
139#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
140#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0
141#else
142#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1
143#endif
144
145#endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H
146
147#ifndef FASTFLOAT_FLOAT_COMMON_H
148#define FASTFLOAT_FLOAT_COMMON_H
149
150#include <cfloat>
151#include <cstdint>
152#include <cassert>
153#include <cstring>
154#include <limits>
155#include <type_traits>
156#include <system_error>
157#ifdef __has_include
158#if __has_include(<stdfloat>) && (__cplusplus > 202002L || (defined(_MSVC_LANG) && (_MSVC_LANG > 202002L)))
159#include <stdfloat>
160#endif
161#endif
162
163#define FASTFLOAT_VERSION_MAJOR 8
164#define FASTFLOAT_VERSION_MINOR 0
165#define FASTFLOAT_VERSION_PATCH 2
166
167#define FASTFLOAT_STRINGIZE_IMPL(x) #x
168#define FASTFLOAT_STRINGIZE(x) FASTFLOAT_STRINGIZE_IMPL(x)
169
170#define FASTFLOAT_VERSION_STR \
171 FASTFLOAT_STRINGIZE(FASTFLOAT_VERSION_MAJOR) \
172 "." FASTFLOAT_STRINGIZE(FASTFLOAT_VERSION_MINOR) "." FASTFLOAT_STRINGIZE( \
173 FASTFLOAT_VERSION_PATCH)
174
175#define FASTFLOAT_VERSION \
176 (FASTFLOAT_VERSION_MAJOR * 10000 + FASTFLOAT_VERSION_MINOR * 100 + \
177 FASTFLOAT_VERSION_PATCH)
178
179namespace fast_float {
180
181enum class chars_format : uint64_t;
182
183namespace detail {
184constexpr chars_format basic_json_fmt = chars_format(1 << 5);
185constexpr chars_format basic_fortran_fmt = chars_format(1 << 6);
186} // namespace detail
187
188enum class chars_format : uint64_t {
189 scientific = 1 << 0,
190 fixed = 1 << 2,
191 hex = 1 << 3,
192 no_infnan = 1 << 4,
193 // RFC 8259: https://datatracker.ietf.org/doc/html/rfc8259#section-6
194 json = uint64_t(detail::basic_json_fmt) | fixed | scientific | no_infnan,
195 // Extension of RFC 8259 where, e.g., "inf" and "nan" are allowed.
196 json_or_infnan = uint64_t(detail::basic_json_fmt) | fixed | scientific,
197 fortran = uint64_t(detail::basic_fortran_fmt) | fixed | scientific,
198 general = fixed | scientific,
199 allow_leading_plus = 1 << 7,
200 skip_white_space = 1 << 8,
201};
202
203template <typename UC> struct from_chars_result_t {
204 UC const *ptr;
205 std::errc ec;
206};
207
208using from_chars_result = from_chars_result_t<char>;
209
210template <typename UC> struct parse_options_t {
211 constexpr explicit parse_options_t(chars_format fmt = chars_format::general,
212 UC dot = UC('.'), int b = 10)
213 : format(fmt), decimal_point(dot), base(b) {}
214
216 chars_format format;
220 int base;
221};
222
223using parse_options = parse_options_t<char>;
224
225} // namespace fast_float
226
227#if FASTFLOAT_HAS_BIT_CAST
228#include <bit>
229#endif
230
231#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
232 defined(__amd64) || defined(__aarch64__) || defined(_M_ARM64) || \
233 defined(__MINGW64__) || defined(__s390x__) || \
234 (defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || \
235 defined(__PPC64LE__)) || \
236 defined(__loongarch64))
237#define FASTFLOAT_64BIT 1
238#elif (defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
239 defined(__arm__) || defined(_M_ARM) || defined(__ppc__) || \
240 defined(__MINGW32__) || defined(__EMSCRIPTEN__))
241#define FASTFLOAT_32BIT 1
242#else
243 // Need to check incrementally, since SIZE_MAX is a size_t, avoid overflow.
244// We can never tell the register width, but the SIZE_MAX is a good
245// approximation. UINTPTR_MAX and INTPTR_MAX are optional, so avoid them for max
246// portability.
247#if SIZE_MAX == 0xffff
248#error Unknown platform (16-bit, unsupported)
249#elif SIZE_MAX == 0xffffffff
250#define FASTFLOAT_32BIT 1
251#elif SIZE_MAX == 0xffffffffffffffff
252#define FASTFLOAT_64BIT 1
253#else
254#error Unknown platform (not 32-bit, not 64-bit?)
255#endif
256#endif
257
258#if ((defined(_WIN32) || defined(_WIN64)) && !defined(__clang__)) || \
259 (defined(_M_ARM64) && !defined(__MINGW32__))
260#include <intrin.h>
261#endif
262
263#if defined(_MSC_VER) && !defined(__clang__)
264#define FASTFLOAT_VISUAL_STUDIO 1
265#endif
266
267#if defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__
268#define FASTFLOAT_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
269#elif defined _WIN32
270#define FASTFLOAT_IS_BIG_ENDIAN 0
271#else
272#if defined(__APPLE__) || defined(__FreeBSD__)
273#include <machine/endian.h>
274#elif defined(sun) || defined(__sun)
275#include <sys/byteorder.h>
276#elif defined(__MVS__)
277#include <sys/endian.h>
278#else
279#ifdef __has_include
280#if __has_include(<endian.h>)
281#include <endian.h>
282#endif //__has_include(<endian.h>)
283#endif //__has_include
284#endif
285#
286#ifndef __BYTE_ORDER__
287// safe choice
288#define FASTFLOAT_IS_BIG_ENDIAN 0
289#endif
290#
291#ifndef __ORDER_LITTLE_ENDIAN__
292// safe choice
293#define FASTFLOAT_IS_BIG_ENDIAN 0
294#endif
295#
296#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
297#define FASTFLOAT_IS_BIG_ENDIAN 0
298#else
299#define FASTFLOAT_IS_BIG_ENDIAN 1
300#endif
301#endif
302
303#if defined(__SSE2__) || (defined(FASTFLOAT_VISUAL_STUDIO) && \
304 (defined(_M_AMD64) || defined(_M_X64) || \
305 (defined(_M_IX86_FP) && _M_IX86_FP == 2)))
306#define FASTFLOAT_SSE2 1
307#endif
308
309#if defined(__aarch64__) || defined(_M_ARM64)
310#define FASTFLOAT_NEON 1
311#endif
312
313#if defined(FASTFLOAT_SSE2) || defined(FASTFLOAT_NEON)
314#define FASTFLOAT_HAS_SIMD 1
315#endif
316
317#if defined(__GNUC__)
318// disable -Wcast-align=strict (GCC only)
319#define FASTFLOAT_SIMD_DISABLE_WARNINGS \
320 _Pragma("GCC diagnostic push") \
321 _Pragma("GCC diagnostic ignored \"-Wcast-align\"")
322#else
323#define FASTFLOAT_SIMD_DISABLE_WARNINGS
324#endif
325
326#if defined(__GNUC__)
327#define FASTFLOAT_SIMD_RESTORE_WARNINGS _Pragma("GCC diagnostic pop")
328#else
329#define FASTFLOAT_SIMD_RESTORE_WARNINGS
330#endif
331
332#ifdef FASTFLOAT_VISUAL_STUDIO
333#define fastfloat_really_inline __forceinline
334#else
335#define fastfloat_really_inline inline __attribute__((always_inline))
336#endif
337
338#ifndef FASTFLOAT_ASSERT
339#define FASTFLOAT_ASSERT(x) \
340 { ((void)(x)); }
341#endif
342
343#ifndef FASTFLOAT_DEBUG_ASSERT
344#define FASTFLOAT_DEBUG_ASSERT(x) \
345 { ((void)(x)); }
346#endif
347
348// rust style `try!()` macro, or `?` operator
349#define FASTFLOAT_TRY(x) \
350 { \
351 if (!(x)) \
352 return false; \
353 }
354
355#define FASTFLOAT_ENABLE_IF(...) \
356 typename std::enable_if<(__VA_ARGS__), int>::type
357
358namespace fast_float {
359
360fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() {
361#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED
362 return std::is_constant_evaluated();
363#else
364 return false;
365#endif
366}
367
368template <typename T>
370 : std::integral_constant<
371 bool, std::is_same<T, double>::value || std::is_same<T, float>::value
372#ifdef __STDCPP_FLOAT64_T__
373 || std::is_same<T, std::float64_t>::value
374#endif
375#ifdef __STDCPP_FLOAT32_T__
376 || std::is_same<T, std::float32_t>::value
377#endif
378#ifdef __STDCPP_FLOAT16_T__
379 || std::is_same<T, std::float16_t>::value
380#endif
381#ifdef __STDCPP_BFLOAT16_T__
382 || std::is_same<T, std::bfloat16_t>::value
383#endif
384 > {
385};
386
387template <typename T>
388using equiv_uint_t = typename std::conditional<
389 sizeof(T) == 1, uint8_t,
390 typename std::conditional<
391 sizeof(T) == 2, uint16_t,
392 typename std::conditional<sizeof(T) == 4, uint32_t,
393 uint64_t>::type>::type>::type;
394
395template <typename T> struct is_supported_integer_type : std::is_integral<T> {};
396
397template <typename UC>
399 : std::integral_constant<bool, std::is_same<UC, char>::value ||
400 std::is_same<UC, wchar_t>::value ||
401 std::is_same<UC, char16_t>::value ||
402 std::is_same<UC, char32_t>::value
403#ifdef __cpp_char8_t
404 || std::is_same<UC, char8_t>::value
405#endif
406 > {
407};
408
409// Compares two ASCII strings in a case insensitive manner.
410template <typename UC>
411inline FASTFLOAT_CONSTEXPR14 bool
412fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase,
413 size_t length) {
414 for (size_t i = 0; i < length; ++i) {
415 UC const actual = actual_mixedcase[i];
416 if ((actual < 256 ? actual | 32 : actual) != expected_lowercase[i]) {
417 return false;
418 }
419 }
420 return true;
421}
422
423#ifndef FLT_EVAL_METHOD
424#error "FLT_EVAL_METHOD should be defined, please include cfloat."
425#endif
426
427// a pointer and a length to a contiguous block of memory
428template <typename T> struct span {
429 T const *ptr;
430 size_t length;
431
432 constexpr span(T const *_ptr, size_t _length) : ptr(_ptr), length(_length) {}
433
434 constexpr span() : ptr(nullptr), length(0) {}
435
436 constexpr size_t len() const noexcept { return length; }
437
438 FASTFLOAT_CONSTEXPR14 const T &operator[](size_t index) const noexcept {
439 FASTFLOAT_DEBUG_ASSERT(index < length);
440 return ptr[index];
441 }
442};
443
444struct value128 {
445 uint64_t low;
446 uint64_t high;
447
448 constexpr value128(uint64_t _low, uint64_t _high) : low(_low), high(_high) {}
449
450 constexpr value128() : low(0), high(0) {}
451};
452
453/* Helper C++14 constexpr generic implementation of leading_zeroes */
454fastfloat_really_inline FASTFLOAT_CONSTEXPR14 int
455leading_zeroes_generic(uint64_t input_num, int last_bit = 0) {
456 if (input_num & uint64_t(0xffffffff00000000)) {
457 input_num >>= 32;
458 last_bit |= 32;
459 }
460 if (input_num & uint64_t(0xffff0000)) {
461 input_num >>= 16;
462 last_bit |= 16;
463 }
464 if (input_num & uint64_t(0xff00)) {
465 input_num >>= 8;
466 last_bit |= 8;
467 }
468 if (input_num & uint64_t(0xf0)) {
469 input_num >>= 4;
470 last_bit |= 4;
471 }
472 if (input_num & uint64_t(0xc)) {
473 input_num >>= 2;
474 last_bit |= 2;
475 }
476 if (input_num & uint64_t(0x2)) { /* input_num >>= 1; */
477 last_bit |= 1;
478 }
479 return 63 - last_bit;
480}
481
482/* result might be undefined when input_num is zero */
483fastfloat_really_inline FASTFLOAT_CONSTEXPR20 int
484leading_zeroes(uint64_t input_num) {
485 assert(input_num > 0);
486 if (cpp20_and_in_constexpr()) {
487 return leading_zeroes_generic(input_num);
488 }
489#ifdef FASTFLOAT_VISUAL_STUDIO
490#if defined(_M_X64) || defined(_M_ARM64)
491 unsigned long leading_zero = 0;
492 // Search the mask data from most significant bit (MSB)
493 // to least significant bit (LSB) for a set bit (1).
494 _BitScanReverse64(&leading_zero, input_num);
495 return (int)(63 - leading_zero);
496#else
497 return leading_zeroes_generic(input_num);
498#endif
499#else
500 return __builtin_clzll(input_num);
501#endif
502}
503
504// slow emulation routine for 32-bit
505fastfloat_really_inline constexpr uint64_t emulu(uint32_t x, uint32_t y) {
506 return x * (uint64_t)y;
507}
508
509fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint64_t
510umul128_generic(uint64_t ab, uint64_t cd, uint64_t *hi) {
511 uint64_t ad = emulu((uint32_t)(ab >> 32), (uint32_t)cd);
512 uint64_t bd = emulu((uint32_t)ab, (uint32_t)cd);
513 uint64_t adbc = ad + emulu((uint32_t)ab, (uint32_t)(cd >> 32));
514 uint64_t adbc_carry = (uint64_t)(adbc < ad);
515 uint64_t lo = bd + (adbc << 32);
516 *hi = emulu((uint32_t)(ab >> 32), (uint32_t)(cd >> 32)) + (adbc >> 32) +
517 (adbc_carry << 32) + (uint64_t)(lo < bd);
518 return lo;
519}
520
521#ifdef FASTFLOAT_32BIT
522
523// slow emulation routine for 32-bit
524#if !defined(__MINGW64__)
525fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint64_t _umul128(uint64_t ab,
526 uint64_t cd,
527 uint64_t *hi) {
528 return umul128_generic(ab, cd, hi);
529}
530#endif // !__MINGW64__
531
532#endif // FASTFLOAT_32BIT
533
534// compute 64-bit a*b
535fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
536full_multiplication(uint64_t a, uint64_t b) {
537 if (cpp20_and_in_constexpr()) {
538 value128 answer;
539 answer.low = umul128_generic(a, b, &answer.high);
540 return answer;
541 }
542 value128 answer;
543#if defined(_M_ARM64) && !defined(__MINGW32__)
544 // ARM64 has native support for 64-bit multiplications, no need to emulate
545 // But MinGW on ARM64 doesn't have native support for 64-bit multiplications
546 answer.high = __umulh(a, b);
547 answer.low = a * b;
548#elif defined(FASTFLOAT_32BIT) || \
549 (defined(_WIN64) && !defined(__clang__) && !defined(_M_ARM64))
550 answer.low = _umul128(a, b, &answer.high); // _umul128 not available on ARM64
551#elif defined(FASTFLOAT_64BIT) && defined(__SIZEOF_INT128__)
552 __uint128_t r = ((__uint128_t)a) * b;
553 answer.low = uint64_t(r);
554 answer.high = uint64_t(r >> 64);
555#else
556 answer.low = umul128_generic(a, b, &answer.high);
557#endif
558 return answer;
559}
560
561struct adjusted_mantissa {
562 uint64_t mantissa{0};
563 int32_t power2{0}; // a negative value indicates an invalid result
564 adjusted_mantissa() = default;
565
566 constexpr bool operator==(adjusted_mantissa const &o) const {
567 return mantissa == o.mantissa && power2 == o.power2;
568 }
569
570 constexpr bool operator!=(adjusted_mantissa const &o) const {
571 return mantissa != o.mantissa || power2 != o.power2;
572 }
573};
574
575// Bias so we can get the real exponent with an invalid adjusted_mantissa.
576constexpr static int32_t invalid_am_bias = -0x8000;
577
578// used for binary_format_lookup_tables<T>::max_mantissa
579constexpr uint64_t constant_55555 = 5 * 5 * 5 * 5 * 5;
580
581template <typename T, typename U = void> struct binary_format_lookup_tables;
582
583template <typename T> struct binary_format : binary_format_lookup_tables<T> {
584 using equiv_uint = equiv_uint_t<T>;
585
586 static constexpr int mantissa_explicit_bits();
587 static constexpr int minimum_exponent();
588 static constexpr int infinite_power();
589 static constexpr int sign_index();
590 static constexpr int
591 min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST
592 static constexpr int max_exponent_fast_path();
593 static constexpr int max_exponent_round_to_even();
594 static constexpr int min_exponent_round_to_even();
595 static constexpr uint64_t max_mantissa_fast_path(int64_t power);
596 static constexpr uint64_t
597 max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST
598 static constexpr int largest_power_of_ten();
599 static constexpr int smallest_power_of_ten();
600 static constexpr T exact_power_of_ten(int64_t power);
601 static constexpr size_t max_digits();
602 static constexpr equiv_uint exponent_mask();
603 static constexpr equiv_uint mantissa_mask();
604 static constexpr equiv_uint hidden_bit_mask();
605};
606
607template <typename U> struct binary_format_lookup_tables<double, U> {
608 static constexpr double powers_of_ten[] = {
609 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
610 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
611
612 // Largest integer value v so that (5**index * v) <= 1<<53.
613 // 0x20000000000000 == 1 << 53
614 static constexpr uint64_t max_mantissa[] = {
615 0x20000000000000,
616 0x20000000000000 / 5,
617 0x20000000000000 / (5 * 5),
618 0x20000000000000 / (5 * 5 * 5),
619 0x20000000000000 / (5 * 5 * 5 * 5),
620 0x20000000000000 / (constant_55555),
621 0x20000000000000 / (constant_55555 * 5),
622 0x20000000000000 / (constant_55555 * 5 * 5),
623 0x20000000000000 / (constant_55555 * 5 * 5 * 5),
624 0x20000000000000 / (constant_55555 * 5 * 5 * 5 * 5),
625 0x20000000000000 / (constant_55555 * constant_55555),
626 0x20000000000000 / (constant_55555 * constant_55555 * 5),
627 0x20000000000000 / (constant_55555 * constant_55555 * 5 * 5),
628 0x20000000000000 / (constant_55555 * constant_55555 * 5 * 5 * 5),
629 0x20000000000000 / (constant_55555 * constant_55555 * constant_55555),
630 0x20000000000000 / (constant_55555 * constant_55555 * constant_55555 * 5),
631 0x20000000000000 /
632 (constant_55555 * constant_55555 * constant_55555 * 5 * 5),
633 0x20000000000000 /
634 (constant_55555 * constant_55555 * constant_55555 * 5 * 5 * 5),
635 0x20000000000000 /
636 (constant_55555 * constant_55555 * constant_55555 * 5 * 5 * 5 * 5),
637 0x20000000000000 /
638 (constant_55555 * constant_55555 * constant_55555 * constant_55555),
639 0x20000000000000 / (constant_55555 * constant_55555 * constant_55555 *
640 constant_55555 * 5),
641 0x20000000000000 / (constant_55555 * constant_55555 * constant_55555 *
642 constant_55555 * 5 * 5),
643 0x20000000000000 / (constant_55555 * constant_55555 * constant_55555 *
644 constant_55555 * 5 * 5 * 5),
645 0x20000000000000 / (constant_55555 * constant_55555 * constant_55555 *
646 constant_55555 * 5 * 5 * 5 * 5)};
647};
648
649#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
650
651template <typename U>
653
654template <typename U>
656
657#endif
658
659template <typename U> struct binary_format_lookup_tables<float, U> {
660 static constexpr float powers_of_ten[] = {1e0f, 1e1f, 1e2f, 1e3f, 1e4f, 1e5f,
661 1e6f, 1e7f, 1e8f, 1e9f, 1e10f};
662
663 // Largest integer value v so that (5**index * v) <= 1<<24.
664 // 0x1000000 == 1<<24
665 static constexpr uint64_t max_mantissa[] = {
666 0x1000000,
667 0x1000000 / 5,
668 0x1000000 / (5 * 5),
669 0x1000000 / (5 * 5 * 5),
670 0x1000000 / (5 * 5 * 5 * 5),
671 0x1000000 / (constant_55555),
672 0x1000000 / (constant_55555 * 5),
673 0x1000000 / (constant_55555 * 5 * 5),
674 0x1000000 / (constant_55555 * 5 * 5 * 5),
675 0x1000000 / (constant_55555 * 5 * 5 * 5 * 5),
676 0x1000000 / (constant_55555 * constant_55555),
677 0x1000000 / (constant_55555 * constant_55555 * 5)};
678};
679
680#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
681
682template <typename U>
684
685template <typename U>
687
688#endif
689
690template <>
691inline constexpr int binary_format<double>::min_exponent_fast_path() {
692#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
693 return 0;
694#else
695 return -22;
696#endif
697}
698
699template <>
700inline constexpr int binary_format<float>::min_exponent_fast_path() {
701#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
702 return 0;
703#else
704 return -10;
705#endif
706}
707
708template <>
709inline constexpr int binary_format<double>::mantissa_explicit_bits() {
710 return 52;
711}
712
713template <>
714inline constexpr int binary_format<float>::mantissa_explicit_bits() {
715 return 23;
716}
717
718template <>
719inline constexpr int binary_format<double>::max_exponent_round_to_even() {
720 return 23;
721}
722
723template <>
724inline constexpr int binary_format<float>::max_exponent_round_to_even() {
725 return 10;
726}
727
728template <>
729inline constexpr int binary_format<double>::min_exponent_round_to_even() {
730 return -4;
731}
732
733template <>
734inline constexpr int binary_format<float>::min_exponent_round_to_even() {
735 return -17;
736}
737
738template <> inline constexpr int binary_format<double>::minimum_exponent() {
739 return -1023;
740}
741
742template <> inline constexpr int binary_format<float>::minimum_exponent() {
743 return -127;
744}
745
746template <> inline constexpr int binary_format<double>::infinite_power() {
747 return 0x7FF;
748}
749
750template <> inline constexpr int binary_format<float>::infinite_power() {
751 return 0xFF;
752}
753
754template <> inline constexpr int binary_format<double>::sign_index() {
755 return 63;
756}
757
758template <> inline constexpr int binary_format<float>::sign_index() {
759 return 31;
760}
761
762template <>
763inline constexpr int binary_format<double>::max_exponent_fast_path() {
764 return 22;
765}
766
767template <>
768inline constexpr int binary_format<float>::max_exponent_fast_path() {
769 return 10;
770}
771
772template <>
773inline constexpr uint64_t binary_format<double>::max_mantissa_fast_path() {
774 return uint64_t(2) << mantissa_explicit_bits();
775}
776
777template <>
778inline constexpr uint64_t binary_format<float>::max_mantissa_fast_path() {
779 return uint64_t(2) << mantissa_explicit_bits();
780}
781
782// credit: Jakub Jelínek
783#ifdef __STDCPP_FLOAT16_T__
784template <typename U> struct binary_format_lookup_tables<std::float16_t, U> {
785 static constexpr std::float16_t powers_of_ten[] = {1e0f16, 1e1f16, 1e2f16,
786 1e3f16, 1e4f16};
787
788 // Largest integer value v so that (5**index * v) <= 1<<11.
789 // 0x800 == 1<<11
790 static constexpr uint64_t max_mantissa[] = {0x800,
791 0x800 / 5,
792 0x800 / (5 * 5),
793 0x800 / (5 * 5 * 5),
794 0x800 / (5 * 5 * 5 * 5),
795 0x800 / (constant_55555)};
796};
797
798#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
799
800template <typename U>
801constexpr std::float16_t
803
804template <typename U>
805constexpr uint64_t
807
808#endif
809
810template <>
811inline constexpr std::float16_t
812binary_format<std::float16_t>::exact_power_of_ten(int64_t power) {
813 // Work around clang bug https://godbolt.org/z/zedh7rrhc
814 return (void)powers_of_ten[0], powers_of_ten[power];
815}
816
817template <>
818inline constexpr binary_format<std::float16_t>::equiv_uint
819binary_format<std::float16_t>::exponent_mask() {
820 return 0x7C00;
821}
822
823template <>
824inline constexpr binary_format<std::float16_t>::equiv_uint
825binary_format<std::float16_t>::mantissa_mask() {
826 return 0x03FF;
827}
828
829template <>
830inline constexpr binary_format<std::float16_t>::equiv_uint
831binary_format<std::float16_t>::hidden_bit_mask() {
832 return 0x0400;
833}
834
835template <>
836inline constexpr int binary_format<std::float16_t>::max_exponent_fast_path() {
837 return 4;
838}
839
840template <>
841inline constexpr int binary_format<std::float16_t>::mantissa_explicit_bits() {
842 return 10;
843}
844
845template <>
846inline constexpr uint64_t
847binary_format<std::float16_t>::max_mantissa_fast_path() {
848 return uint64_t(2) << mantissa_explicit_bits();
849}
850
851template <>
852inline constexpr uint64_t
853binary_format<std::float16_t>::max_mantissa_fast_path(int64_t power) {
854 // caller is responsible to ensure that
855 // power >= 0 && power <= 4
856 //
857 // Work around clang bug https://godbolt.org/z/zedh7rrhc
858 return (void)max_mantissa[0], max_mantissa[power];
859}
860
861template <>
862inline constexpr int binary_format<std::float16_t>::min_exponent_fast_path() {
863 return 0;
864}
865
866template <>
867inline constexpr int
868binary_format<std::float16_t>::max_exponent_round_to_even() {
869 return 5;
870}
871
872template <>
873inline constexpr int
874binary_format<std::float16_t>::min_exponent_round_to_even() {
875 return -22;
876}
877
878template <>
879inline constexpr int binary_format<std::float16_t>::minimum_exponent() {
880 return -15;
881}
882
883template <>
884inline constexpr int binary_format<std::float16_t>::infinite_power() {
885 return 0x1F;
886}
887
888template <> inline constexpr int binary_format<std::float16_t>::sign_index() {
889 return 15;
890}
891
892template <>
893inline constexpr int binary_format<std::float16_t>::largest_power_of_ten() {
894 return 4;
895}
896
897template <>
898inline constexpr int binary_format<std::float16_t>::smallest_power_of_ten() {
899 return -27;
900}
901
902template <>
903inline constexpr size_t binary_format<std::float16_t>::max_digits() {
904 return 22;
905}
906#endif // __STDCPP_FLOAT16_T__
907
908// credit: Jakub Jelínek
909#ifdef __STDCPP_BFLOAT16_T__
910template <typename U> struct binary_format_lookup_tables<std::bfloat16_t, U> {
911 static constexpr std::bfloat16_t powers_of_ten[] = {1e0bf16, 1e1bf16, 1e2bf16,
912 1e3bf16};
913
914 // Largest integer value v so that (5**index * v) <= 1<<8.
915 // 0x100 == 1<<8
916 static constexpr uint64_t max_mantissa[] = {0x100, 0x100 / 5, 0x100 / (5 * 5),
917 0x100 / (5 * 5 * 5),
918 0x100 / (5 * 5 * 5 * 5)};
919};
920
921#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
922
923template <typename U>
924constexpr std::bfloat16_t
926
927template <typename U>
928constexpr uint64_t
930
931#endif
932
933template <>
934inline constexpr std::bfloat16_t
935binary_format<std::bfloat16_t>::exact_power_of_ten(int64_t power) {
936 // Work around clang bug https://godbolt.org/z/zedh7rrhc
937 return (void)powers_of_ten[0], powers_of_ten[power];
938}
939
940template <>
941inline constexpr int binary_format<std::bfloat16_t>::max_exponent_fast_path() {
942 return 3;
943}
944
945template <>
946inline constexpr binary_format<std::bfloat16_t>::equiv_uint
947binary_format<std::bfloat16_t>::exponent_mask() {
948 return 0x7F80;
949}
950
951template <>
952inline constexpr binary_format<std::bfloat16_t>::equiv_uint
953binary_format<std::bfloat16_t>::mantissa_mask() {
954 return 0x007F;
955}
956
957template <>
958inline constexpr binary_format<std::bfloat16_t>::equiv_uint
959binary_format<std::bfloat16_t>::hidden_bit_mask() {
960 return 0x0080;
961}
962
963template <>
964inline constexpr int binary_format<std::bfloat16_t>::mantissa_explicit_bits() {
965 return 7;
966}
967
968template <>
969inline constexpr uint64_t
970binary_format<std::bfloat16_t>::max_mantissa_fast_path() {
971 return uint64_t(2) << mantissa_explicit_bits();
972}
973
974template <>
975inline constexpr uint64_t
976binary_format<std::bfloat16_t>::max_mantissa_fast_path(int64_t power) {
977 // caller is responsible to ensure that
978 // power >= 0 && power <= 3
979 //
980 // Work around clang bug https://godbolt.org/z/zedh7rrhc
981 return (void)max_mantissa[0], max_mantissa[power];
982}
983
984template <>
985inline constexpr int binary_format<std::bfloat16_t>::min_exponent_fast_path() {
986 return 0;
987}
988
989template <>
990inline constexpr int
991binary_format<std::bfloat16_t>::max_exponent_round_to_even() {
992 return 3;
993}
994
995template <>
996inline constexpr int
997binary_format<std::bfloat16_t>::min_exponent_round_to_even() {
998 return -24;
999}
1000
1001template <>
1002inline constexpr int binary_format<std::bfloat16_t>::minimum_exponent() {
1003 return -127;
1004}
1005
1006template <>
1007inline constexpr int binary_format<std::bfloat16_t>::infinite_power() {
1008 return 0xFF;
1009}
1010
1011template <> inline constexpr int binary_format<std::bfloat16_t>::sign_index() {
1012 return 15;
1013}
1014
1015template <>
1016inline constexpr int binary_format<std::bfloat16_t>::largest_power_of_ten() {
1017 return 38;
1018}
1019
1020template <>
1021inline constexpr int binary_format<std::bfloat16_t>::smallest_power_of_ten() {
1022 return -60;
1023}
1024
1025template <>
1026inline constexpr size_t binary_format<std::bfloat16_t>::max_digits() {
1027 return 98;
1028}
1029#endif // __STDCPP_BFLOAT16_T__
1030
1031template <>
1032inline constexpr uint64_t
1033binary_format<double>::max_mantissa_fast_path(int64_t power) {
1034 // caller is responsible to ensure that
1035 // power >= 0 && power <= 22
1036 //
1037 // Work around clang bug https://godbolt.org/z/zedh7rrhc
1038 return (void)max_mantissa[0], max_mantissa[power];
1039}
1040
1041template <>
1042inline constexpr uint64_t
1043binary_format<float>::max_mantissa_fast_path(int64_t power) {
1044 // caller is responsible to ensure that
1045 // power >= 0 && power <= 10
1046 //
1047 // Work around clang bug https://godbolt.org/z/zedh7rrhc
1048 return (void)max_mantissa[0], max_mantissa[power];
1049}
1050
1051template <>
1052inline constexpr double
1053binary_format<double>::exact_power_of_ten(int64_t power) {
1054 // Work around clang bug https://godbolt.org/z/zedh7rrhc
1055 return (void)powers_of_ten[0], powers_of_ten[power];
1056}
1057
1058template <>
1059inline constexpr float binary_format<float>::exact_power_of_ten(int64_t power) {
1060 // Work around clang bug https://godbolt.org/z/zedh7rrhc
1061 return (void)powers_of_ten[0], powers_of_ten[power];
1062}
1063
1064template <> inline constexpr int binary_format<double>::largest_power_of_ten() {
1065 return 308;
1066}
1067
1068template <> inline constexpr int binary_format<float>::largest_power_of_ten() {
1069 return 38;
1070}
1071
1072template <>
1073inline constexpr int binary_format<double>::smallest_power_of_ten() {
1074 return -342;
1075}
1076
1077template <> inline constexpr int binary_format<float>::smallest_power_of_ten() {
1078 return -64;
1079}
1080
1081template <> inline constexpr size_t binary_format<double>::max_digits() {
1082 return 769;
1083}
1084
1085template <> inline constexpr size_t binary_format<float>::max_digits() {
1086 return 114;
1087}
1088
1089template <>
1090inline constexpr binary_format<float>::equiv_uint
1091binary_format<float>::exponent_mask() {
1092 return 0x7F800000;
1093}
1094
1095template <>
1096inline constexpr binary_format<double>::equiv_uint
1097binary_format<double>::exponent_mask() {
1098 return 0x7FF0000000000000;
1099}
1100
1101template <>
1102inline constexpr binary_format<float>::equiv_uint
1103binary_format<float>::mantissa_mask() {
1104 return 0x007FFFFF;
1105}
1106
1107template <>
1108inline constexpr binary_format<double>::equiv_uint
1109binary_format<double>::mantissa_mask() {
1110 return 0x000FFFFFFFFFFFFF;
1111}
1112
1113template <>
1114inline constexpr binary_format<float>::equiv_uint
1115binary_format<float>::hidden_bit_mask() {
1116 return 0x00800000;
1117}
1118
1119template <>
1120inline constexpr binary_format<double>::equiv_uint
1121binary_format<double>::hidden_bit_mask() {
1122 return 0x0010000000000000;
1123}
1124
1125template <typename T>
1126fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
1127to_float(bool negative, adjusted_mantissa am, T &value) {
1128 using equiv_uint = equiv_uint_t<T>;
1129 equiv_uint word = equiv_uint(am.mantissa);
1130 word = equiv_uint(word | equiv_uint(am.power2)
1131 << binary_format<T>::mantissa_explicit_bits());
1132 word =
1133 equiv_uint(word | equiv_uint(negative) << binary_format<T>::sign_index());
1134#if FASTFLOAT_HAS_BIT_CAST
1135 value = std::bit_cast<T>(word);
1136#else
1137 ::memcpy(&value, &word, sizeof(T));
1138#endif
1139}
1140
1141template <typename = void> struct space_lut {
1142 static constexpr bool value[] = {
1143 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1144 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1154};
1155
1156#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
1157
1158template <typename T> constexpr bool space_lut<T>::value[];
1159
1160#endif
1161
1162template <typename UC> constexpr bool is_space(UC c) {
1163 return c < 256 && space_lut<>::value[uint8_t(c)];
1164}
1165
1166template <typename UC> static constexpr uint64_t int_cmp_zeros() {
1167 static_assert((sizeof(UC) == 1) || (sizeof(UC) == 2) || (sizeof(UC) == 4),
1168 "Unsupported character size");
1169 return (sizeof(UC) == 1) ? 0x3030303030303030
1170 : (sizeof(UC) == 2)
1171 ? (uint64_t(UC('0')) << 48 | uint64_t(UC('0')) << 32 |
1172 uint64_t(UC('0')) << 16 | UC('0'))
1173 : (uint64_t(UC('0')) << 32 | UC('0'));
1174}
1175
1176template <typename UC> static constexpr int int_cmp_len() {
1177 return sizeof(uint64_t) / sizeof(UC);
1178}
1179
1180template <typename UC> constexpr UC const *str_const_nan();
1181
1182template <> constexpr char const *str_const_nan<char>() { return "nan"; }
1183
1184template <> constexpr wchar_t const *str_const_nan<wchar_t>() { return L"nan"; }
1185
1186template <> constexpr char16_t const *str_const_nan<char16_t>() {
1187 return u"nan";
1188}
1189
1190template <> constexpr char32_t const *str_const_nan<char32_t>() {
1191 return U"nan";
1192}
1193
1194#ifdef __cpp_char8_t
1195template <> constexpr char8_t const *str_const_nan<char8_t>() {
1196 return u8"nan";
1197}
1198#endif
1199
1200template <typename UC> constexpr UC const *str_const_inf();
1201
1202template <> constexpr char const *str_const_inf<char>() { return "infinity"; }
1203
1204template <> constexpr wchar_t const *str_const_inf<wchar_t>() {
1205 return L"infinity";
1206}
1207
1208template <> constexpr char16_t const *str_const_inf<char16_t>() {
1209 return u"infinity";
1210}
1211
1212template <> constexpr char32_t const *str_const_inf<char32_t>() {
1213 return U"infinity";
1214}
1215
1216#ifdef __cpp_char8_t
1217template <> constexpr char8_t const *str_const_inf<char8_t>() {
1218 return u8"infinity";
1219}
1220#endif
1221
1222template <typename = void> struct int_luts {
1223 static constexpr uint8_t chdigit[] = {
1224 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1225 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1226 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1227 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255,
1228 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1229 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
1230 35, 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 16, 17,
1231 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
1232 33, 34, 35, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1233 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1234 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1235 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1236 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1237 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1238 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1239 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1240 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
1241 255};
1242
1243 static constexpr size_t maxdigits_u64[] = {
1244 64, 41, 32, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 16, 16, 16, 16,
1245 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13};
1246
1247 static constexpr uint64_t min_safe_u64[] = {
1248 9223372036854775808ull, 12157665459056928801ull, 4611686018427387904,
1249 7450580596923828125, 4738381338321616896, 3909821048582988049,
1250 9223372036854775808ull, 12157665459056928801ull, 10000000000000000000ull,
1251 5559917313492231481, 2218611106740436992, 8650415919381337933,
1252 2177953337809371136, 6568408355712890625, 1152921504606846976,
1253 2862423051509815793, 6746640616477458432, 15181127029874798299ull,
1254 1638400000000000000, 3243919932521508681, 6221821273427820544,
1255 11592836324538749809ull, 876488338465357824, 1490116119384765625,
1256 2481152873203736576, 4052555153018976267, 6502111422497947648,
1257 10260628712958602189ull, 15943230000000000000ull, 787662783788549761,
1258 1152921504606846976, 1667889514952984961, 2386420683693101056,
1259 3379220508056640625, 4738381338321616896};
1260};
1261
1262#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
1263
1264template <typename T> constexpr uint8_t int_luts<T>::chdigit[];
1265
1266template <typename T> constexpr size_t int_luts<T>::maxdigits_u64[];
1267
1268template <typename T> constexpr uint64_t int_luts<T>::min_safe_u64[];
1269
1270#endif
1271
1272template <typename UC>
1273fastfloat_really_inline constexpr uint8_t ch_to_digit(UC c) {
1274 return int_luts<>::chdigit[static_cast<unsigned char>(c)];
1275}
1276
1277fastfloat_really_inline constexpr size_t max_digits_u64(int base) {
1278 return int_luts<>::maxdigits_u64[base - 2];
1279}
1280
1281// If a u64 is exactly max_digits_u64() in length, this is
1282// the value below which it has definitely overflowed.
1283fastfloat_really_inline constexpr uint64_t min_safe_u64(int base) {
1284 return int_luts<>::min_safe_u64[base - 2];
1285}
1286
1287static_assert(std::is_same<equiv_uint_t<double>, uint64_t>::value,
1288 "equiv_uint should be uint64_t for double");
1289static_assert(std::numeric_limits<double>::is_iec559,
1290 "double must fulfill the requirements of IEC 559 (IEEE 754)");
1291
1292static_assert(std::is_same<equiv_uint_t<float>, uint32_t>::value,
1293 "equiv_uint should be uint32_t for float");
1294static_assert(std::numeric_limits<float>::is_iec559,
1295 "float must fulfill the requirements of IEC 559 (IEEE 754)");
1296
1297#ifdef __STDCPP_FLOAT64_T__
1298static_assert(std::is_same<equiv_uint_t<std::float64_t>, uint64_t>::value,
1299 "equiv_uint should be uint64_t for std::float64_t");
1300static_assert(
1301 std::numeric_limits<std::float64_t>::is_iec559,
1302 "std::float64_t must fulfill the requirements of IEC 559 (IEEE 754)");
1303#endif // __STDCPP_FLOAT64_T__
1304
1305#ifdef __STDCPP_FLOAT32_T__
1306static_assert(std::is_same<equiv_uint_t<std::float32_t>, uint32_t>::value,
1307 "equiv_uint should be uint32_t for std::float32_t");
1308static_assert(
1309 std::numeric_limits<std::float32_t>::is_iec559,
1310 "std::float32_t must fulfill the requirements of IEC 559 (IEEE 754)");
1311#endif // __STDCPP_FLOAT32_T__
1312
1313#ifdef __STDCPP_FLOAT16_T__
1314static_assert(
1315 std::is_same<binary_format<std::float16_t>::equiv_uint, uint16_t>::value,
1316 "equiv_uint should be uint16_t for std::float16_t");
1317static_assert(
1318 std::numeric_limits<std::float16_t>::is_iec559,
1319 "std::float16_t must fulfill the requirements of IEC 559 (IEEE 754)");
1320#endif // __STDCPP_FLOAT16_T__
1321
1322#ifdef __STDCPP_BFLOAT16_T__
1323static_assert(
1324 std::is_same<binary_format<std::bfloat16_t>::equiv_uint, uint16_t>::value,
1325 "equiv_uint should be uint16_t for std::bfloat16_t");
1326static_assert(
1327 std::numeric_limits<std::bfloat16_t>::is_iec559,
1328 "std::bfloat16_t must fulfill the requirements of IEC 559 (IEEE 754)");
1329#endif // __STDCPP_BFLOAT16_T__
1330
1331constexpr chars_format operator~(chars_format rhs) noexcept {
1332 using int_type = std::underlying_type<chars_format>::type;
1333 return static_cast<chars_format>(~static_cast<int_type>(rhs));
1334}
1335
1336constexpr chars_format operator&(chars_format lhs, chars_format rhs) noexcept {
1337 using int_type = std::underlying_type<chars_format>::type;
1338 return static_cast<chars_format>(static_cast<int_type>(lhs) &
1339 static_cast<int_type>(rhs));
1340}
1341
1342constexpr chars_format operator|(chars_format lhs, chars_format rhs) noexcept {
1343 using int_type = std::underlying_type<chars_format>::type;
1344 return static_cast<chars_format>(static_cast<int_type>(lhs) |
1345 static_cast<int_type>(rhs));
1346}
1347
1348constexpr chars_format operator^(chars_format lhs, chars_format rhs) noexcept {
1349 using int_type = std::underlying_type<chars_format>::type;
1350 return static_cast<chars_format>(static_cast<int_type>(lhs) ^
1351 static_cast<int_type>(rhs));
1352}
1353
1354fastfloat_really_inline FASTFLOAT_CONSTEXPR14 chars_format &
1355operator&=(chars_format &lhs, chars_format rhs) noexcept {
1356 return lhs = (lhs & rhs);
1357}
1358
1359fastfloat_really_inline FASTFLOAT_CONSTEXPR14 chars_format &
1360operator|=(chars_format &lhs, chars_format rhs) noexcept {
1361 return lhs = (lhs | rhs);
1362}
1363
1364fastfloat_really_inline FASTFLOAT_CONSTEXPR14 chars_format &
1365operator^=(chars_format &lhs, chars_format rhs) noexcept {
1366 return lhs = (lhs ^ rhs);
1367}
1368
1369namespace detail {
1370// adjust for deprecated feature macros
1371constexpr chars_format adjust_for_feature_macros(chars_format fmt) {
1372 return fmt
1373#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS
1374 | chars_format::allow_leading_plus
1375#endif
1376#ifdef FASTFLOAT_SKIP_WHITE_SPACE
1377 | chars_format::skip_white_space
1378#endif
1379 ;
1380}
1381} // namespace detail
1382
1383} // namespace fast_float
1384
1385#endif
1386
1387
1388#ifndef FASTFLOAT_FAST_FLOAT_H
1389#define FASTFLOAT_FAST_FLOAT_H
1390
1391
1392namespace fast_float {
1418template <typename T, typename UC = char,
1419 typename = FASTFLOAT_ENABLE_IF(is_supported_float_type<T>::value)>
1420FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
1421from_chars(UC const *first, UC const *last, T &value,
1422 chars_format fmt = chars_format::general) noexcept;
1423
1428template <typename T, typename UC = char>
1429FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
1430from_chars_advanced(UC const *first, UC const *last, T &value,
1431 parse_options_t<UC> options) noexcept;
1432
1436template <typename T, typename UC = char,
1437 typename = FASTFLOAT_ENABLE_IF(is_supported_integer_type<T>::value)>
1438FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
1439from_chars(UC const *first, UC const *last, T &value, int base = 10) noexcept;
1440
1441} // namespace fast_float
1442
1443#endif // FASTFLOAT_FAST_FLOAT_H
1444
1445#ifndef FASTFLOAT_ASCII_NUMBER_H
1446#define FASTFLOAT_ASCII_NUMBER_H
1447
1448#include <cctype>
1449#include <cstdint>
1450#include <cstring>
1451#include <iterator>
1452#include <limits>
1453#include <type_traits>
1454
1455
1456#ifdef FASTFLOAT_SSE2
1457#include <emmintrin.h>
1458#endif
1459
1460#ifdef FASTFLOAT_NEON
1461#include <arm_neon.h>
1462#endif
1463
1464namespace fast_float {
1465
1466template <typename UC> fastfloat_really_inline constexpr bool has_simd_opt() {
1467#ifdef FASTFLOAT_HAS_SIMD
1468 return std::is_same<UC, char16_t>::value;
1469#else
1470 return false;
1471#endif
1472}
1473
1474// Next function can be micro-optimized, but compilers are entirely
1475// able to optimize it well.
1476template <typename UC>
1477fastfloat_really_inline constexpr bool is_integer(UC c) noexcept {
1478 return !(c > UC('9') || c < UC('0'));
1479}
1480
1481fastfloat_really_inline constexpr uint64_t byteswap(uint64_t val) {
1482 return (val & 0xFF00000000000000) >> 56 | (val & 0x00FF000000000000) >> 40 |
1483 (val & 0x0000FF0000000000) >> 24 | (val & 0x000000FF00000000) >> 8 |
1484 (val & 0x00000000FF000000) << 8 | (val & 0x0000000000FF0000) << 24 |
1485 (val & 0x000000000000FF00) << 40 | (val & 0x00000000000000FF) << 56;
1486}
1487
1488// Read 8 UC into a u64. Truncates UC if not char.
1489template <typename UC>
1490fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
1491read8_to_u64(UC const *chars) {
1492 if (cpp20_and_in_constexpr() || !std::is_same<UC, char>::value) {
1493 uint64_t val = 0;
1494 for (int i = 0; i < 8; ++i) {
1495 val |= uint64_t(uint8_t(*chars)) << (i * 8);
1496 ++chars;
1497 }
1498 return val;
1499 }
1500 uint64_t val;
1501 ::memcpy(&val, chars, sizeof(uint64_t));
1502#if FASTFLOAT_IS_BIG_ENDIAN == 1
1503 // Need to read as-if the number was in little-endian order.
1504 val = byteswap(val);
1505#endif
1506 return val;
1507}
1508
1509#ifdef FASTFLOAT_SSE2
1510
1511fastfloat_really_inline uint64_t simd_read8_to_u64(__m128i const data) {
1512 FASTFLOAT_SIMD_DISABLE_WARNINGS
1513 __m128i const packed = _mm_packus_epi16(data, data);
1514#ifdef FASTFLOAT_64BIT
1515 return uint64_t(_mm_cvtsi128_si64(packed));
1516#else
1517 uint64_t value;
1518 // Visual Studio + older versions of GCC don't support _mm_storeu_si64
1519 _mm_storel_epi64(reinterpret_cast<__m128i *>(&value), packed);
1520 return value;
1521#endif
1522 FASTFLOAT_SIMD_RESTORE_WARNINGS
1523}
1524
1525fastfloat_really_inline uint64_t simd_read8_to_u64(char16_t const *chars) {
1526 FASTFLOAT_SIMD_DISABLE_WARNINGS
1527 return simd_read8_to_u64(
1528 _mm_loadu_si128(reinterpret_cast<__m128i const *>(chars)));
1529 FASTFLOAT_SIMD_RESTORE_WARNINGS
1530}
1531
1532#elif defined(FASTFLOAT_NEON)
1533
1534fastfloat_really_inline uint64_t simd_read8_to_u64(uint16x8_t const data) {
1535 FASTFLOAT_SIMD_DISABLE_WARNINGS
1536 uint8x8_t utf8_packed = vmovn_u16(data);
1537 return vget_lane_u64(vreinterpret_u64_u8(utf8_packed), 0);
1538 FASTFLOAT_SIMD_RESTORE_WARNINGS
1539}
1540
1541fastfloat_really_inline uint64_t simd_read8_to_u64(char16_t const *chars) {
1542 FASTFLOAT_SIMD_DISABLE_WARNINGS
1543 return simd_read8_to_u64(
1544 vld1q_u16(reinterpret_cast<uint16_t const *>(chars)));
1545 FASTFLOAT_SIMD_RESTORE_WARNINGS
1546}
1547
1548#endif // FASTFLOAT_SSE2
1549
1550// MSVC SFINAE is broken pre-VS2017
1551#if defined(_MSC_VER) && _MSC_VER <= 1900
1552template <typename UC>
1553#else
1554template <typename UC, FASTFLOAT_ENABLE_IF(!has_simd_opt<UC>()) = 0>
1555#endif
1556// dummy for compile
1557uint64_t simd_read8_to_u64(UC const *) {
1558 return 0;
1559}
1560
1561// credit @aqrit
1562fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint32_t
1563parse_eight_digits_unrolled(uint64_t val) {
1564 uint64_t const mask = 0x000000FF000000FF;
1565 uint64_t const mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
1566 uint64_t const mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
1567 val -= 0x3030303030303030;
1568 val = (val * 10) + (val >> 8); // val = (val * 2561) >> 8;
1569 val = (((val & mask) * mul1) + (((val >> 16) & mask) * mul2)) >> 32;
1570 return uint32_t(val);
1571}
1572
1573// Call this if chars are definitely 8 digits.
1574template <typename UC>
1575fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint32_t
1576parse_eight_digits_unrolled(UC const *chars) noexcept {
1577 if (cpp20_and_in_constexpr() || !has_simd_opt<UC>()) {
1578 return parse_eight_digits_unrolled(read8_to_u64(chars)); // truncation okay
1579 }
1580 return parse_eight_digits_unrolled(simd_read8_to_u64(chars));
1581}
1582
1583// credit @aqrit
1584fastfloat_really_inline constexpr bool
1585is_made_of_eight_digits_fast(uint64_t val) noexcept {
1586 return !((((val + 0x4646464646464646) | (val - 0x3030303030303030)) &
1587 0x8080808080808080));
1588}
1589
1590#ifdef FASTFLOAT_HAS_SIMD
1591
1592// Call this if chars might not be 8 digits.
1593// Using this style (instead of is_made_of_eight_digits_fast() then
1594// parse_eight_digits_unrolled()) ensures we don't load SIMD registers twice.
1595fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool
1596simd_parse_if_eight_digits_unrolled(char16_t const *chars,
1597 uint64_t &i) noexcept {
1598 if (cpp20_and_in_constexpr()) {
1599 return false;
1600 }
1601#ifdef FASTFLOAT_SSE2
1602 FASTFLOAT_SIMD_DISABLE_WARNINGS
1603 __m128i const data =
1604 _mm_loadu_si128(reinterpret_cast<__m128i const *>(chars));
1605
1606 // (x - '0') <= 9
1607 // http://0x80.pl/articles/simd-parsing-int-sequences.html
1608 __m128i const t0 = _mm_add_epi16(data, _mm_set1_epi16(32720));
1609 __m128i const t1 = _mm_cmpgt_epi16(t0, _mm_set1_epi16(-32759));
1610
1611 if (_mm_movemask_epi8(t1) == 0) {
1612 i = i * 100000000 + parse_eight_digits_unrolled(simd_read8_to_u64(data));
1613 return true;
1614 } else
1615 return false;
1616 FASTFLOAT_SIMD_RESTORE_WARNINGS
1617#elif defined(FASTFLOAT_NEON)
1618 FASTFLOAT_SIMD_DISABLE_WARNINGS
1619 uint16x8_t const data = vld1q_u16(reinterpret_cast<uint16_t const *>(chars));
1620
1621 // (x - '0') <= 9
1622 // http://0x80.pl/articles/simd-parsing-int-sequences.html
1623 uint16x8_t const t0 = vsubq_u16(data, vmovq_n_u16('0'));
1624 uint16x8_t const mask = vcltq_u16(t0, vmovq_n_u16('9' - '0' + 1));
1625
1626 if (vminvq_u16(mask) == 0xFFFF) {
1627 i = i * 100000000 + parse_eight_digits_unrolled(simd_read8_to_u64(data));
1628 return true;
1629 } else
1630 return false;
1631 FASTFLOAT_SIMD_RESTORE_WARNINGS
1632#else
1633 (void)chars;
1634 (void)i;
1635 return false;
1636#endif // FASTFLOAT_SSE2
1637}
1638
1639#endif // FASTFLOAT_HAS_SIMD
1640
1641// MSVC SFINAE is broken pre-VS2017
1642#if defined(_MSC_VER) && _MSC_VER <= 1900
1643template <typename UC>
1644#else
1645template <typename UC, FASTFLOAT_ENABLE_IF(!has_simd_opt<UC>()) = 0>
1646#endif
1647// dummy for compile
1648bool simd_parse_if_eight_digits_unrolled(UC const *, uint64_t &) {
1649 return 0;
1650}
1651
1652template <typename UC, FASTFLOAT_ENABLE_IF(!std::is_same<UC, char>::value) = 0>
1653fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
1654loop_parse_if_eight_digits(UC const *&p, UC const *const pend, uint64_t &i) {
1655 if (!has_simd_opt<UC>()) {
1656 return;
1657 }
1658 while ((std::distance(p, pend) >= 8) &&
1659 simd_parse_if_eight_digits_unrolled(
1660 p, i)) { // in rare cases, this will overflow, but that's ok
1661 p += 8;
1662 }
1663}
1664
1665fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
1666loop_parse_if_eight_digits(char const *&p, char const *const pend,
1667 uint64_t &i) {
1668 // optimizes better than parse_if_eight_digits_unrolled() for UC = char.
1669 while ((std::distance(p, pend) >= 8) &&
1670 is_made_of_eight_digits_fast(read8_to_u64(p))) {
1671 i = i * 100000000 +
1672 parse_eight_digits_unrolled(read8_to_u64(
1673 p)); // in rare cases, this will overflow, but that's ok
1674 p += 8;
1675 }
1676}
1677
1678enum class parse_error {
1679 no_error,
1680 // [JSON-only] The minus sign must be followed by an integer.
1681 missing_integer_after_sign,
1682 // A sign must be followed by an integer or dot.
1683 missing_integer_or_dot_after_sign,
1684 // [JSON-only] The integer part must not have leading zeros.
1685 leading_zeros_in_integer_part,
1686 // [JSON-only] The integer part must have at least one digit.
1687 no_digits_in_integer_part,
1688 // [JSON-only] If there is a decimal point, there must be digits in the
1689 // fractional part.
1690 no_digits_in_fractional_part,
1691 // The mantissa must have at least one digit.
1692 no_digits_in_mantissa,
1693 // Scientific notation requires an exponential part.
1694 missing_exponential_part,
1695};
1696
1697template <typename UC> struct parsed_number_string_t {
1698 int64_t exponent{0};
1699 uint64_t mantissa{0};
1700 UC const *lastmatch{nullptr};
1701 bool negative{false};
1702 bool valid{false};
1703 bool too_many_digits{false};
1704 // contains the range of the significant digits
1705 span<UC const> integer{}; // non-nullable
1706 span<UC const> fraction{}; // nullable
1707 parse_error error{parse_error::no_error};
1708};
1709
1710using byte_span = span<char const>;
1711using parsed_number_string = parsed_number_string_t<char>;
1712
1713template <typename UC>
1714fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
1715report_parse_error(UC const *p, parse_error error) {
1717 answer.valid = false;
1718 answer.lastmatch = p;
1719 answer.error = error;
1720 return answer;
1721}
1722
1723// Assuming that you use no more than 19 digits, this will
1724// parse an ASCII string.
1725template <bool basic_json_fmt, typename UC>
1726fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
1727parse_number_string(UC const *p, UC const *pend,
1728 parse_options_t<UC> options) noexcept {
1729 chars_format const fmt = detail::adjust_for_feature_macros(options.format);
1730 UC const decimal_point = options.decimal_point;
1731
1732 parsed_number_string_t<UC> answer;
1733 answer.valid = false;
1734 answer.too_many_digits = false;
1735 // assume p < pend, so dereference without checks;
1736 answer.negative = (*p == UC('-'));
1737 // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
1738 if ((*p == UC('-')) || (uint64_t(fmt & chars_format::allow_leading_plus) &&
1739 !basic_json_fmt && *p == UC('+'))) {
1740 ++p;
1741 if (p == pend) {
1742 return report_parse_error<UC>(
1743 p, parse_error::missing_integer_or_dot_after_sign);
1744 }
1745 FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
1746 if (!is_integer(*p)) { // a sign must be followed by an integer
1747 return report_parse_error<UC>(p,
1748 parse_error::missing_integer_after_sign);
1749 }
1750 }
1751 else {
1752 if (!is_integer(*p) &&
1753 (*p !=
1754 decimal_point)) { // a sign must be followed by an integer or the dot
1755 return report_parse_error<UC>(
1756 p, parse_error::missing_integer_or_dot_after_sign);
1757 }
1758 }
1759 }
1760 UC const *const start_digits = p;
1761
1762 uint64_t i = 0; // an unsigned int avoids signed overflows (which are bad)
1763
1764 while ((p != pend) && is_integer(*p)) {
1765 // a multiplication by 10 is cheaper than an arbitrary integer
1766 // multiplication
1767 i = 10 * i +
1768 uint64_t(*p -
1769 UC('0')); // might overflow, we will handle the overflow later
1770 ++p;
1771 }
1772 UC const *const end_of_integer_part = p;
1773 int64_t digit_count = int64_t(end_of_integer_part - start_digits);
1774 answer.integer = span<UC const>(start_digits, size_t(digit_count));
1775 FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
1776 // at least 1 digit in integer part, without leading zeros
1777 if (digit_count == 0) {
1778 return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
1779 }
1780 if ((start_digits[0] == UC('0') && digit_count > 1)) {
1781 return report_parse_error<UC>(start_digits,
1782 parse_error::leading_zeros_in_integer_part);
1783 }
1784 }
1785
1786 int64_t exponent = 0;
1787 bool const has_decimal_point = (p != pend) && (*p == decimal_point);
1788 if (has_decimal_point) {
1789 ++p;
1790 UC const *before = p;
1791 // can occur at most twice without overflowing, but let it occur more, since
1792 // for integers with many digits, digit parsing is the primary bottleneck.
1793 loop_parse_if_eight_digits(p, pend, i);
1794
1795 while ((p != pend) && is_integer(*p)) {
1796 uint8_t digit = uint8_t(*p - UC('0'));
1797 ++p;
1798 i = i * 10 + digit; // in rare cases, this will overflow, but that's ok
1799 }
1800 exponent = before - p;
1801 answer.fraction = span<UC const>(before, size_t(p - before));
1802 digit_count -= exponent;
1803 }
1804 FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
1805 // at least 1 digit in fractional part
1806 if (has_decimal_point && exponent == 0) {
1807 return report_parse_error<UC>(p,
1808 parse_error::no_digits_in_fractional_part);
1809 }
1810 }
1811 else if (digit_count == 0) { // we must have encountered at least one integer!
1812 return report_parse_error<UC>(p, parse_error::no_digits_in_mantissa);
1813 }
1814 int64_t exp_number = 0; // explicit exponential part
1815 if ((uint64_t(fmt & chars_format::scientific) && (p != pend) &&
1816 ((UC('e') == *p) || (UC('E') == *p))) ||
1817 (uint64_t(fmt & detail::basic_fortran_fmt) && (p != pend) &&
1818 ((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) ||
1819 (UC('D') == *p)))) {
1820 UC const *location_of_e = p;
1821 if ((UC('e') == *p) || (UC('E') == *p) || (UC('d') == *p) ||
1822 (UC('D') == *p)) {
1823 ++p;
1824 }
1825 bool neg_exp = false;
1826 if ((p != pend) && (UC('-') == *p)) {
1827 neg_exp = true;
1828 ++p;
1829 } else if ((p != pend) &&
1830 (UC('+') ==
1831 *p)) { // '+' on exponent is allowed by C++17 20.19.3.(7.1)
1832 ++p;
1833 }
1834 if ((p == pend) || !is_integer(*p)) {
1835 if (!uint64_t(fmt & chars_format::fixed)) {
1836 // The exponential part is invalid for scientific notation, so it must
1837 // be a trailing token for fixed notation. However, fixed notation is
1838 // disabled, so report a scientific notation error.
1839 return report_parse_error<UC>(p, parse_error::missing_exponential_part);
1840 }
1841 // Otherwise, we will be ignoring the 'e'.
1842 p = location_of_e;
1843 } else {
1844 while ((p != pend) && is_integer(*p)) {
1845 uint8_t digit = uint8_t(*p - UC('0'));
1846 if (exp_number < 0x10000000) {
1847 exp_number = 10 * exp_number + digit;
1848 }
1849 ++p;
1850 }
1851 if (neg_exp) {
1852 exp_number = -exp_number;
1853 }
1854 exponent += exp_number;
1855 }
1856 } else {
1857 // If it scientific and not fixed, we have to bail out.
1858 if (uint64_t(fmt & chars_format::scientific) &&
1859 !uint64_t(fmt & chars_format::fixed)) {
1860 return report_parse_error<UC>(p, parse_error::missing_exponential_part);
1861 }
1862 }
1863 answer.lastmatch = p;
1864 answer.valid = true;
1865
1866 // If we frequently had to deal with long strings of digits,
1867 // we could extend our code by using a 128-bit integer instead
1868 // of a 64-bit integer. However, this is uncommon.
1869 //
1870 // We can deal with up to 19 digits.
1871 if (digit_count > 19) { // this is uncommon
1872 // It is possible that the integer had an overflow.
1873 // We have to handle the case where we have 0.0000somenumber.
1874 // We need to be mindful of the case where we only have zeroes...
1875 // E.g., 0.000000000...000.
1876 UC const *start = start_digits;
1877 while ((start != pend) && (*start == UC('0') || *start == decimal_point)) {
1878 if (*start == UC('0')) {
1879 digit_count--;
1880 }
1881 start++;
1882 }
1883
1884 if (digit_count > 19) {
1885 answer.too_many_digits = true;
1886 // Let us start again, this time, avoiding overflows.
1887 // We don't need to check if is_integer, since we use the
1888 // pre-tokenized spans from above.
1889 i = 0;
1890 p = answer.integer.ptr;
1891 UC const *int_end = p + answer.integer.len();
1892 uint64_t const minimal_nineteen_digit_integer{1000000000000000000};
1893 while ((i < minimal_nineteen_digit_integer) && (p != int_end)) {
1894 i = i * 10 + uint64_t(*p - UC('0'));
1895 ++p;
1896 }
1897 if (i >= minimal_nineteen_digit_integer) { // We have a big integers
1898 exponent = end_of_integer_part - p + exp_number;
1899 } else { // We have a value with a fractional component.
1900 p = answer.fraction.ptr;
1901 UC const *frac_end = p + answer.fraction.len();
1902 while ((i < minimal_nineteen_digit_integer) && (p != frac_end)) {
1903 i = i * 10 + uint64_t(*p - UC('0'));
1904 ++p;
1905 }
1906 exponent = answer.fraction.ptr - p + exp_number;
1907 }
1908 // We have now corrected both exponent and i, to a truncated value
1909 }
1910 }
1911 answer.exponent = exponent;
1912 answer.mantissa = i;
1913 return answer;
1914}
1915
1916template <typename T, typename UC>
1917fastfloat_really_inline FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
1918parse_int_string(UC const *p, UC const *pend, T &value,
1919 parse_options_t<UC> options) {
1920 chars_format const fmt = detail::adjust_for_feature_macros(options.format);
1921 int const base = options.base;
1922
1924
1925 UC const *const first = p;
1926
1927 bool const negative = (*p == UC('-'));
1928#ifdef FASTFLOAT_VISUAL_STUDIO
1929#pragma warning(push)
1930#pragma warning(disable : 4127)
1931#endif
1932 if (!std::is_signed<T>::value && negative) {
1933#ifdef FASTFLOAT_VISUAL_STUDIO
1934#pragma warning(pop)
1935#endif
1936 answer.ec = std::errc::invalid_argument;
1937 answer.ptr = first;
1938 return answer;
1939 }
1940 if ((*p == UC('-')) ||
1941 (uint64_t(fmt & chars_format::allow_leading_plus) && (*p == UC('+')))) {
1942 ++p;
1943 }
1944
1945 UC const *const start_num = p;
1946
1947 while (p != pend && *p == UC('0')) {
1948 ++p;
1949 }
1950
1951 bool const has_leading_zeros = p > start_num;
1952
1953 UC const *const start_digits = p;
1954
1955 uint64_t i = 0;
1956 if (base == 10) {
1957 loop_parse_if_eight_digits(p, pend, i); // use SIMD if possible
1958 }
1959 while (p != pend) {
1960 uint8_t digit = ch_to_digit(*p);
1961 if (digit >= base) {
1962 break;
1963 }
1964 i = uint64_t(base) * i + digit; // might overflow, check this later
1965 p++;
1966 }
1967
1968 size_t digit_count = size_t(p - start_digits);
1969
1970 if (digit_count == 0) {
1971 if (has_leading_zeros) {
1972 value = 0;
1973 answer.ec = std::errc();
1974 answer.ptr = p;
1975 } else {
1976 answer.ec = std::errc::invalid_argument;
1977 answer.ptr = first;
1978 }
1979 return answer;
1980 }
1981
1982 answer.ptr = p;
1983
1984 // check u64 overflow
1985 size_t max_digits = max_digits_u64(base);
1986 if (digit_count > max_digits) {
1987 answer.ec = std::errc::result_out_of_range;
1988 return answer;
1989 }
1990 // this check can be eliminated for all other types, but they will all require
1991 // a max_digits(base) equivalent
1992 if (digit_count == max_digits && i < min_safe_u64(base)) {
1993 answer.ec = std::errc::result_out_of_range;
1994 return answer;
1995 }
1996
1997 // check other types overflow
1998 if (!std::is_same<T, uint64_t>::value) {
1999 if (i > uint64_t(std::numeric_limits<T>::max()) + uint64_t(negative)) {
2000 answer.ec = std::errc::result_out_of_range;
2001 return answer;
2002 }
2003 }
2004
2005 if (negative) {
2006#ifdef FASTFLOAT_VISUAL_STUDIO
2007#pragma warning(push)
2008#pragma warning(disable : 4146)
2009#endif
2010 // this weird workaround is required because:
2011 // - converting unsigned to signed when its value is greater than signed max
2012 // is UB pre-C++23.
2013 // - reinterpret_casting (~i + 1) would work, but it is not constexpr
2014 // this is always optimized into a neg instruction (note: T is an integer
2015 // type)
2016 value = T(-std::numeric_limits<T>::max() -
2017 T(i - uint64_t(std::numeric_limits<T>::max())));
2018#ifdef FASTFLOAT_VISUAL_STUDIO
2019#pragma warning(pop)
2020#endif
2021 } else {
2022 value = T(i);
2023 }
2024
2025 answer.ec = std::errc();
2026 return answer;
2027}
2028
2029} // namespace fast_float
2030
2031#endif
2032
2033#ifndef FASTFLOAT_FAST_TABLE_H
2034#define FASTFLOAT_FAST_TABLE_H
2035
2036#include <cstdint>
2037
2038namespace fast_float {
2039
2050
2064template <class unused = void> struct powers_template {
2065
2066 constexpr static int smallest_power_of_five =
2067 binary_format<double>::smallest_power_of_ten();
2068 constexpr static int largest_power_of_five =
2069 binary_format<double>::largest_power_of_ten();
2070 constexpr static int number_of_entries =
2071 2 * (largest_power_of_five - smallest_power_of_five + 1);
2072 // Powers of five from 5^-342 all the way to 5^308 rounded toward one.
2073 constexpr static uint64_t power_of_five_128[number_of_entries] = {
2074 0xeef453d6923bd65a, 0x113faa2906a13b3f,
2075 0x9558b4661b6565f8, 0x4ac7ca59a424c507,
2076 0xbaaee17fa23ebf76, 0x5d79bcf00d2df649,
2077 0xe95a99df8ace6f53, 0xf4d82c2c107973dc,
2078 0x91d8a02bb6c10594, 0x79071b9b8a4be869,
2079 0xb64ec836a47146f9, 0x9748e2826cdee284,
2080 0xe3e27a444d8d98b7, 0xfd1b1b2308169b25,
2081 0x8e6d8c6ab0787f72, 0xfe30f0f5e50e20f7,
2082 0xb208ef855c969f4f, 0xbdbd2d335e51a935,
2083 0xde8b2b66b3bc4723, 0xad2c788035e61382,
2084 0x8b16fb203055ac76, 0x4c3bcb5021afcc31,
2085 0xaddcb9e83c6b1793, 0xdf4abe242a1bbf3d,
2086 0xd953e8624b85dd78, 0xd71d6dad34a2af0d,
2087 0x87d4713d6f33aa6b, 0x8672648c40e5ad68,
2088 0xa9c98d8ccb009506, 0x680efdaf511f18c2,
2089 0xd43bf0effdc0ba48, 0x212bd1b2566def2,
2090 0x84a57695fe98746d, 0x14bb630f7604b57,
2091 0xa5ced43b7e3e9188, 0x419ea3bd35385e2d,
2092 0xcf42894a5dce35ea, 0x52064cac828675b9,
2093 0x818995ce7aa0e1b2, 0x7343efebd1940993,
2094 0xa1ebfb4219491a1f, 0x1014ebe6c5f90bf8,
2095 0xca66fa129f9b60a6, 0xd41a26e077774ef6,
2096 0xfd00b897478238d0, 0x8920b098955522b4,
2097 0x9e20735e8cb16382, 0x55b46e5f5d5535b0,
2098 0xc5a890362fddbc62, 0xeb2189f734aa831d,
2099 0xf712b443bbd52b7b, 0xa5e9ec7501d523e4,
2100 0x9a6bb0aa55653b2d, 0x47b233c92125366e,
2101 0xc1069cd4eabe89f8, 0x999ec0bb696e840a,
2102 0xf148440a256e2c76, 0xc00670ea43ca250d,
2103 0x96cd2a865764dbca, 0x380406926a5e5728,
2104 0xbc807527ed3e12bc, 0xc605083704f5ecf2,
2105 0xeba09271e88d976b, 0xf7864a44c633682e,
2106 0x93445b8731587ea3, 0x7ab3ee6afbe0211d,
2107 0xb8157268fdae9e4c, 0x5960ea05bad82964,
2108 0xe61acf033d1a45df, 0x6fb92487298e33bd,
2109 0x8fd0c16206306bab, 0xa5d3b6d479f8e056,
2110 0xb3c4f1ba87bc8696, 0x8f48a4899877186c,
2111 0xe0b62e2929aba83c, 0x331acdabfe94de87,
2112 0x8c71dcd9ba0b4925, 0x9ff0c08b7f1d0b14,
2113 0xaf8e5410288e1b6f, 0x7ecf0ae5ee44dd9,
2114 0xdb71e91432b1a24a, 0xc9e82cd9f69d6150,
2115 0x892731ac9faf056e, 0xbe311c083a225cd2,
2116 0xab70fe17c79ac6ca, 0x6dbd630a48aaf406,
2117 0xd64d3d9db981787d, 0x92cbbccdad5b108,
2118 0x85f0468293f0eb4e, 0x25bbf56008c58ea5,
2119 0xa76c582338ed2621, 0xaf2af2b80af6f24e,
2120 0xd1476e2c07286faa, 0x1af5af660db4aee1,
2121 0x82cca4db847945ca, 0x50d98d9fc890ed4d,
2122 0xa37fce126597973c, 0xe50ff107bab528a0,
2123 0xcc5fc196fefd7d0c, 0x1e53ed49a96272c8,
2124 0xff77b1fcbebcdc4f, 0x25e8e89c13bb0f7a,
2125 0x9faacf3df73609b1, 0x77b191618c54e9ac,
2126 0xc795830d75038c1d, 0xd59df5b9ef6a2417,
2127 0xf97ae3d0d2446f25, 0x4b0573286b44ad1d,
2128 0x9becce62836ac577, 0x4ee367f9430aec32,
2129 0xc2e801fb244576d5, 0x229c41f793cda73f,
2130 0xf3a20279ed56d48a, 0x6b43527578c1110f,
2131 0x9845418c345644d6, 0x830a13896b78aaa9,
2132 0xbe5691ef416bd60c, 0x23cc986bc656d553,
2133 0xedec366b11c6cb8f, 0x2cbfbe86b7ec8aa8,
2134 0x94b3a202eb1c3f39, 0x7bf7d71432f3d6a9,
2135 0xb9e08a83a5e34f07, 0xdaf5ccd93fb0cc53,
2136 0xe858ad248f5c22c9, 0xd1b3400f8f9cff68,
2137 0x91376c36d99995be, 0x23100809b9c21fa1,
2138 0xb58547448ffffb2d, 0xabd40a0c2832a78a,
2139 0xe2e69915b3fff9f9, 0x16c90c8f323f516c,
2140 0x8dd01fad907ffc3b, 0xae3da7d97f6792e3,
2141 0xb1442798f49ffb4a, 0x99cd11cfdf41779c,
2142 0xdd95317f31c7fa1d, 0x40405643d711d583,
2143 0x8a7d3eef7f1cfc52, 0x482835ea666b2572,
2144 0xad1c8eab5ee43b66, 0xda3243650005eecf,
2145 0xd863b256369d4a40, 0x90bed43e40076a82,
2146 0x873e4f75e2224e68, 0x5a7744a6e804a291,
2147 0xa90de3535aaae202, 0x711515d0a205cb36,
2148 0xd3515c2831559a83, 0xd5a5b44ca873e03,
2149 0x8412d9991ed58091, 0xe858790afe9486c2,
2150 0xa5178fff668ae0b6, 0x626e974dbe39a872,
2151 0xce5d73ff402d98e3, 0xfb0a3d212dc8128f,
2152 0x80fa687f881c7f8e, 0x7ce66634bc9d0b99,
2153 0xa139029f6a239f72, 0x1c1fffc1ebc44e80,
2154 0xc987434744ac874e, 0xa327ffb266b56220,
2155 0xfbe9141915d7a922, 0x4bf1ff9f0062baa8,
2156 0x9d71ac8fada6c9b5, 0x6f773fc3603db4a9,
2157 0xc4ce17b399107c22, 0xcb550fb4384d21d3,
2158 0xf6019da07f549b2b, 0x7e2a53a146606a48,
2159 0x99c102844f94e0fb, 0x2eda7444cbfc426d,
2160 0xc0314325637a1939, 0xfa911155fefb5308,
2161 0xf03d93eebc589f88, 0x793555ab7eba27ca,
2162 0x96267c7535b763b5, 0x4bc1558b2f3458de,
2163 0xbbb01b9283253ca2, 0x9eb1aaedfb016f16,
2164 0xea9c227723ee8bcb, 0x465e15a979c1cadc,
2165 0x92a1958a7675175f, 0xbfacd89ec191ec9,
2166 0xb749faed14125d36, 0xcef980ec671f667b,
2167 0xe51c79a85916f484, 0x82b7e12780e7401a,
2168 0x8f31cc0937ae58d2, 0xd1b2ecb8b0908810,
2169 0xb2fe3f0b8599ef07, 0x861fa7e6dcb4aa15,
2170 0xdfbdcece67006ac9, 0x67a791e093e1d49a,
2171 0x8bd6a141006042bd, 0xe0c8bb2c5c6d24e0,
2172 0xaecc49914078536d, 0x58fae9f773886e18,
2173 0xda7f5bf590966848, 0xaf39a475506a899e,
2174 0x888f99797a5e012d, 0x6d8406c952429603,
2175 0xaab37fd7d8f58178, 0xc8e5087ba6d33b83,
2176 0xd5605fcdcf32e1d6, 0xfb1e4a9a90880a64,
2177 0x855c3be0a17fcd26, 0x5cf2eea09a55067f,
2178 0xa6b34ad8c9dfc06f, 0xf42faa48c0ea481e,
2179 0xd0601d8efc57b08b, 0xf13b94daf124da26,
2180 0x823c12795db6ce57, 0x76c53d08d6b70858,
2181 0xa2cb1717b52481ed, 0x54768c4b0c64ca6e,
2182 0xcb7ddcdda26da268, 0xa9942f5dcf7dfd09,
2183 0xfe5d54150b090b02, 0xd3f93b35435d7c4c,
2184 0x9efa548d26e5a6e1, 0xc47bc5014a1a6daf,
2185 0xc6b8e9b0709f109a, 0x359ab6419ca1091b,
2186 0xf867241c8cc6d4c0, 0xc30163d203c94b62,
2187 0x9b407691d7fc44f8, 0x79e0de63425dcf1d,
2188 0xc21094364dfb5636, 0x985915fc12f542e4,
2189 0xf294b943e17a2bc4, 0x3e6f5b7b17b2939d,
2190 0x979cf3ca6cec5b5a, 0xa705992ceecf9c42,
2191 0xbd8430bd08277231, 0x50c6ff782a838353,
2192 0xece53cec4a314ebd, 0xa4f8bf5635246428,
2193 0x940f4613ae5ed136, 0x871b7795e136be99,
2194 0xb913179899f68584, 0x28e2557b59846e3f,
2195 0xe757dd7ec07426e5, 0x331aeada2fe589cf,
2196 0x9096ea6f3848984f, 0x3ff0d2c85def7621,
2197 0xb4bca50b065abe63, 0xfed077a756b53a9,
2198 0xe1ebce4dc7f16dfb, 0xd3e8495912c62894,
2199 0x8d3360f09cf6e4bd, 0x64712dd7abbbd95c,
2200 0xb080392cc4349dec, 0xbd8d794d96aacfb3,
2201 0xdca04777f541c567, 0xecf0d7a0fc5583a0,
2202 0x89e42caaf9491b60, 0xf41686c49db57244,
2203 0xac5d37d5b79b6239, 0x311c2875c522ced5,
2204 0xd77485cb25823ac7, 0x7d633293366b828b,
2205 0x86a8d39ef77164bc, 0xae5dff9c02033197,
2206 0xa8530886b54dbdeb, 0xd9f57f830283fdfc,
2207 0xd267caa862a12d66, 0xd072df63c324fd7b,
2208 0x8380dea93da4bc60, 0x4247cb9e59f71e6d,
2209 0xa46116538d0deb78, 0x52d9be85f074e608,
2210 0xcd795be870516656, 0x67902e276c921f8b,
2211 0x806bd9714632dff6, 0xba1cd8a3db53b6,
2212 0xa086cfcd97bf97f3, 0x80e8a40eccd228a4,
2213 0xc8a883c0fdaf7df0, 0x6122cd128006b2cd,
2214 0xfad2a4b13d1b5d6c, 0x796b805720085f81,
2215 0x9cc3a6eec6311a63, 0xcbe3303674053bb0,
2216 0xc3f490aa77bd60fc, 0xbedbfc4411068a9c,
2217 0xf4f1b4d515acb93b, 0xee92fb5515482d44,
2218 0x991711052d8bf3c5, 0x751bdd152d4d1c4a,
2219 0xbf5cd54678eef0b6, 0xd262d45a78a0635d,
2220 0xef340a98172aace4, 0x86fb897116c87c34,
2221 0x9580869f0e7aac0e, 0xd45d35e6ae3d4da0,
2222 0xbae0a846d2195712, 0x8974836059cca109,
2223 0xe998d258869facd7, 0x2bd1a438703fc94b,
2224 0x91ff83775423cc06, 0x7b6306a34627ddcf,
2225 0xb67f6455292cbf08, 0x1a3bc84c17b1d542,
2226 0xe41f3d6a7377eeca, 0x20caba5f1d9e4a93,
2227 0x8e938662882af53e, 0x547eb47b7282ee9c,
2228 0xb23867fb2a35b28d, 0xe99e619a4f23aa43,
2229 0xdec681f9f4c31f31, 0x6405fa00e2ec94d4,
2230 0x8b3c113c38f9f37e, 0xde83bc408dd3dd04,
2231 0xae0b158b4738705e, 0x9624ab50b148d445,
2232 0xd98ddaee19068c76, 0x3badd624dd9b0957,
2233 0x87f8a8d4cfa417c9, 0xe54ca5d70a80e5d6,
2234 0xa9f6d30a038d1dbc, 0x5e9fcf4ccd211f4c,
2235 0xd47487cc8470652b, 0x7647c3200069671f,
2236 0x84c8d4dfd2c63f3b, 0x29ecd9f40041e073,
2237 0xa5fb0a17c777cf09, 0xf468107100525890,
2238 0xcf79cc9db955c2cc, 0x7182148d4066eeb4,
2239 0x81ac1fe293d599bf, 0xc6f14cd848405530,
2240 0xa21727db38cb002f, 0xb8ada00e5a506a7c,
2241 0xca9cf1d206fdc03b, 0xa6d90811f0e4851c,
2242 0xfd442e4688bd304a, 0x908f4a166d1da663,
2243 0x9e4a9cec15763e2e, 0x9a598e4e043287fe,
2244 0xc5dd44271ad3cdba, 0x40eff1e1853f29fd,
2245 0xf7549530e188c128, 0xd12bee59e68ef47c,
2246 0x9a94dd3e8cf578b9, 0x82bb74f8301958ce,
2247 0xc13a148e3032d6e7, 0xe36a52363c1faf01,
2248 0xf18899b1bc3f8ca1, 0xdc44e6c3cb279ac1,
2249 0x96f5600f15a7b7e5, 0x29ab103a5ef8c0b9,
2250 0xbcb2b812db11a5de, 0x7415d448f6b6f0e7,
2251 0xebdf661791d60f56, 0x111b495b3464ad21,
2252 0x936b9fcebb25c995, 0xcab10dd900beec34,
2253 0xb84687c269ef3bfb, 0x3d5d514f40eea742,
2254 0xe65829b3046b0afa, 0xcb4a5a3112a5112,
2255 0x8ff71a0fe2c2e6dc, 0x47f0e785eaba72ab,
2256 0xb3f4e093db73a093, 0x59ed216765690f56,
2257 0xe0f218b8d25088b8, 0x306869c13ec3532c,
2258 0x8c974f7383725573, 0x1e414218c73a13fb,
2259 0xafbd2350644eeacf, 0xe5d1929ef90898fa,
2260 0xdbac6c247d62a583, 0xdf45f746b74abf39,
2261 0x894bc396ce5da772, 0x6b8bba8c328eb783,
2262 0xab9eb47c81f5114f, 0x66ea92f3f326564,
2263 0xd686619ba27255a2, 0xc80a537b0efefebd,
2264 0x8613fd0145877585, 0xbd06742ce95f5f36,
2265 0xa798fc4196e952e7, 0x2c48113823b73704,
2266 0xd17f3b51fca3a7a0, 0xf75a15862ca504c5,
2267 0x82ef85133de648c4, 0x9a984d73dbe722fb,
2268 0xa3ab66580d5fdaf5, 0xc13e60d0d2e0ebba,
2269 0xcc963fee10b7d1b3, 0x318df905079926a8,
2270 0xffbbcfe994e5c61f, 0xfdf17746497f7052,
2271 0x9fd561f1fd0f9bd3, 0xfeb6ea8bedefa633,
2272 0xc7caba6e7c5382c8, 0xfe64a52ee96b8fc0,
2273 0xf9bd690a1b68637b, 0x3dfdce7aa3c673b0,
2274 0x9c1661a651213e2d, 0x6bea10ca65c084e,
2275 0xc31bfa0fe5698db8, 0x486e494fcff30a62,
2276 0xf3e2f893dec3f126, 0x5a89dba3c3efccfa,
2277 0x986ddb5c6b3a76b7, 0xf89629465a75e01c,
2278 0xbe89523386091465, 0xf6bbb397f1135823,
2279 0xee2ba6c0678b597f, 0x746aa07ded582e2c,
2280 0x94db483840b717ef, 0xa8c2a44eb4571cdc,
2281 0xba121a4650e4ddeb, 0x92f34d62616ce413,
2282 0xe896a0d7e51e1566, 0x77b020baf9c81d17,
2283 0x915e2486ef32cd60, 0xace1474dc1d122e,
2284 0xb5b5ada8aaff80b8, 0xd819992132456ba,
2285 0xe3231912d5bf60e6, 0x10e1fff697ed6c69,
2286 0x8df5efabc5979c8f, 0xca8d3ffa1ef463c1,
2287 0xb1736b96b6fd83b3, 0xbd308ff8a6b17cb2,
2288 0xddd0467c64bce4a0, 0xac7cb3f6d05ddbde,
2289 0x8aa22c0dbef60ee4, 0x6bcdf07a423aa96b,
2290 0xad4ab7112eb3929d, 0x86c16c98d2c953c6,
2291 0xd89d64d57a607744, 0xe871c7bf077ba8b7,
2292 0x87625f056c7c4a8b, 0x11471cd764ad4972,
2293 0xa93af6c6c79b5d2d, 0xd598e40d3dd89bcf,
2294 0xd389b47879823479, 0x4aff1d108d4ec2c3,
2295 0x843610cb4bf160cb, 0xcedf722a585139ba,
2296 0xa54394fe1eedb8fe, 0xc2974eb4ee658828,
2297 0xce947a3da6a9273e, 0x733d226229feea32,
2298 0x811ccc668829b887, 0x806357d5a3f525f,
2299 0xa163ff802a3426a8, 0xca07c2dcb0cf26f7,
2300 0xc9bcff6034c13052, 0xfc89b393dd02f0b5,
2301 0xfc2c3f3841f17c67, 0xbbac2078d443ace2,
2302 0x9d9ba7832936edc0, 0xd54b944b84aa4c0d,
2303 0xc5029163f384a931, 0xa9e795e65d4df11,
2304 0xf64335bcf065d37d, 0x4d4617b5ff4a16d5,
2305 0x99ea0196163fa42e, 0x504bced1bf8e4e45,
2306 0xc06481fb9bcf8d39, 0xe45ec2862f71e1d6,
2307 0xf07da27a82c37088, 0x5d767327bb4e5a4c,
2308 0x964e858c91ba2655, 0x3a6a07f8d510f86f,
2309 0xbbe226efb628afea, 0x890489f70a55368b,
2310 0xeadab0aba3b2dbe5, 0x2b45ac74ccea842e,
2311 0x92c8ae6b464fc96f, 0x3b0b8bc90012929d,
2312 0xb77ada0617e3bbcb, 0x9ce6ebb40173744,
2313 0xe55990879ddcaabd, 0xcc420a6a101d0515,
2314 0x8f57fa54c2a9eab6, 0x9fa946824a12232d,
2315 0xb32df8e9f3546564, 0x47939822dc96abf9,
2316 0xdff9772470297ebd, 0x59787e2b93bc56f7,
2317 0x8bfbea76c619ef36, 0x57eb4edb3c55b65a,
2318 0xaefae51477a06b03, 0xede622920b6b23f1,
2319 0xdab99e59958885c4, 0xe95fab368e45eced,
2320 0x88b402f7fd75539b, 0x11dbcb0218ebb414,
2321 0xaae103b5fcd2a881, 0xd652bdc29f26a119,
2322 0xd59944a37c0752a2, 0x4be76d3346f0495f,
2323 0x857fcae62d8493a5, 0x6f70a4400c562ddb,
2324 0xa6dfbd9fb8e5b88e, 0xcb4ccd500f6bb952,
2325 0xd097ad07a71f26b2, 0x7e2000a41346a7a7,
2326 0x825ecc24c873782f, 0x8ed400668c0c28c8,
2327 0xa2f67f2dfa90563b, 0x728900802f0f32fa,
2328 0xcbb41ef979346bca, 0x4f2b40a03ad2ffb9,
2329 0xfea126b7d78186bc, 0xe2f610c84987bfa8,
2330 0x9f24b832e6b0f436, 0xdd9ca7d2df4d7c9,
2331 0xc6ede63fa05d3143, 0x91503d1c79720dbb,
2332 0xf8a95fcf88747d94, 0x75a44c6397ce912a,
2333 0x9b69dbe1b548ce7c, 0xc986afbe3ee11aba,
2334 0xc24452da229b021b, 0xfbe85badce996168,
2335 0xf2d56790ab41c2a2, 0xfae27299423fb9c3,
2336 0x97c560ba6b0919a5, 0xdccd879fc967d41a,
2337 0xbdb6b8e905cb600f, 0x5400e987bbc1c920,
2338 0xed246723473e3813, 0x290123e9aab23b68,
2339 0x9436c0760c86e30b, 0xf9a0b6720aaf6521,
2340 0xb94470938fa89bce, 0xf808e40e8d5b3e69,
2341 0xe7958cb87392c2c2, 0xb60b1d1230b20e04,
2342 0x90bd77f3483bb9b9, 0xb1c6f22b5e6f48c2,
2343 0xb4ecd5f01a4aa828, 0x1e38aeb6360b1af3,
2344 0xe2280b6c20dd5232, 0x25c6da63c38de1b0,
2345 0x8d590723948a535f, 0x579c487e5a38ad0e,
2346 0xb0af48ec79ace837, 0x2d835a9df0c6d851,
2347 0xdcdb1b2798182244, 0xf8e431456cf88e65,
2348 0x8a08f0f8bf0f156b, 0x1b8e9ecb641b58ff,
2349 0xac8b2d36eed2dac5, 0xe272467e3d222f3f,
2350 0xd7adf884aa879177, 0x5b0ed81dcc6abb0f,
2351 0x86ccbb52ea94baea, 0x98e947129fc2b4e9,
2352 0xa87fea27a539e9a5, 0x3f2398d747b36224,
2353 0xd29fe4b18e88640e, 0x8eec7f0d19a03aad,
2354 0x83a3eeeef9153e89, 0x1953cf68300424ac,
2355 0xa48ceaaab75a8e2b, 0x5fa8c3423c052dd7,
2356 0xcdb02555653131b6, 0x3792f412cb06794d,
2357 0x808e17555f3ebf11, 0xe2bbd88bbee40bd0,
2358 0xa0b19d2ab70e6ed6, 0x5b6aceaeae9d0ec4,
2359 0xc8de047564d20a8b, 0xf245825a5a445275,
2360 0xfb158592be068d2e, 0xeed6e2f0f0d56712,
2361 0x9ced737bb6c4183d, 0x55464dd69685606b,
2362 0xc428d05aa4751e4c, 0xaa97e14c3c26b886,
2363 0xf53304714d9265df, 0xd53dd99f4b3066a8,
2364 0x993fe2c6d07b7fab, 0xe546a8038efe4029,
2365 0xbf8fdb78849a5f96, 0xde98520472bdd033,
2366 0xef73d256a5c0f77c, 0x963e66858f6d4440,
2367 0x95a8637627989aad, 0xdde7001379a44aa8,
2368 0xbb127c53b17ec159, 0x5560c018580d5d52,
2369 0xe9d71b689dde71af, 0xaab8f01e6e10b4a6,
2370 0x9226712162ab070d, 0xcab3961304ca70e8,
2371 0xb6b00d69bb55c8d1, 0x3d607b97c5fd0d22,
2372 0xe45c10c42a2b3b05, 0x8cb89a7db77c506a,
2373 0x8eb98a7a9a5b04e3, 0x77f3608e92adb242,
2374 0xb267ed1940f1c61c, 0x55f038b237591ed3,
2375 0xdf01e85f912e37a3, 0x6b6c46dec52f6688,
2376 0x8b61313bbabce2c6, 0x2323ac4b3b3da015,
2377 0xae397d8aa96c1b77, 0xabec975e0a0d081a,
2378 0xd9c7dced53c72255, 0x96e7bd358c904a21,
2379 0x881cea14545c7575, 0x7e50d64177da2e54,
2380 0xaa242499697392d2, 0xdde50bd1d5d0b9e9,
2381 0xd4ad2dbfc3d07787, 0x955e4ec64b44e864,
2382 0x84ec3c97da624ab4, 0xbd5af13bef0b113e,
2383 0xa6274bbdd0fadd61, 0xecb1ad8aeacdd58e,
2384 0xcfb11ead453994ba, 0x67de18eda5814af2,
2385 0x81ceb32c4b43fcf4, 0x80eacf948770ced7,
2386 0xa2425ff75e14fc31, 0xa1258379a94d028d,
2387 0xcad2f7f5359a3b3e, 0x96ee45813a04330,
2388 0xfd87b5f28300ca0d, 0x8bca9d6e188853fc,
2389 0x9e74d1b791e07e48, 0x775ea264cf55347e,
2390 0xc612062576589dda, 0x95364afe032a819e,
2391 0xf79687aed3eec551, 0x3a83ddbd83f52205,
2392 0x9abe14cd44753b52, 0xc4926a9672793543,
2393 0xc16d9a0095928a27, 0x75b7053c0f178294,
2394 0xf1c90080baf72cb1, 0x5324c68b12dd6339,
2395 0x971da05074da7bee, 0xd3f6fc16ebca5e04,
2396 0xbce5086492111aea, 0x88f4bb1ca6bcf585,
2397 0xec1e4a7db69561a5, 0x2b31e9e3d06c32e6,
2398 0x9392ee8e921d5d07, 0x3aff322e62439fd0,
2399 0xb877aa3236a4b449, 0x9befeb9fad487c3,
2400 0xe69594bec44de15b, 0x4c2ebe687989a9b4,
2401 0x901d7cf73ab0acd9, 0xf9d37014bf60a11,
2402 0xb424dc35095cd80f, 0x538484c19ef38c95,
2403 0xe12e13424bb40e13, 0x2865a5f206b06fba,
2404 0x8cbccc096f5088cb, 0xf93f87b7442e45d4,
2405 0xafebff0bcb24aafe, 0xf78f69a51539d749,
2406 0xdbe6fecebdedd5be, 0xb573440e5a884d1c,
2407 0x89705f4136b4a597, 0x31680a88f8953031,
2408 0xabcc77118461cefc, 0xfdc20d2b36ba7c3e,
2409 0xd6bf94d5e57a42bc, 0x3d32907604691b4d,
2410 0x8637bd05af6c69b5, 0xa63f9a49c2c1b110,
2411 0xa7c5ac471b478423, 0xfcf80dc33721d54,
2412 0xd1b71758e219652b, 0xd3c36113404ea4a9,
2413 0x83126e978d4fdf3b, 0x645a1cac083126ea,
2414 0xa3d70a3d70a3d70a, 0x3d70a3d70a3d70a4,
2415 0xcccccccccccccccc, 0xcccccccccccccccd,
2416 0x8000000000000000, 0x0,
2417 0xa000000000000000, 0x0,
2418 0xc800000000000000, 0x0,
2419 0xfa00000000000000, 0x0,
2420 0x9c40000000000000, 0x0,
2421 0xc350000000000000, 0x0,
2422 0xf424000000000000, 0x0,
2423 0x9896800000000000, 0x0,
2424 0xbebc200000000000, 0x0,
2425 0xee6b280000000000, 0x0,
2426 0x9502f90000000000, 0x0,
2427 0xba43b74000000000, 0x0,
2428 0xe8d4a51000000000, 0x0,
2429 0x9184e72a00000000, 0x0,
2430 0xb5e620f480000000, 0x0,
2431 0xe35fa931a0000000, 0x0,
2432 0x8e1bc9bf04000000, 0x0,
2433 0xb1a2bc2ec5000000, 0x0,
2434 0xde0b6b3a76400000, 0x0,
2435 0x8ac7230489e80000, 0x0,
2436 0xad78ebc5ac620000, 0x0,
2437 0xd8d726b7177a8000, 0x0,
2438 0x878678326eac9000, 0x0,
2439 0xa968163f0a57b400, 0x0,
2440 0xd3c21bcecceda100, 0x0,
2441 0x84595161401484a0, 0x0,
2442 0xa56fa5b99019a5c8, 0x0,
2443 0xcecb8f27f4200f3a, 0x0,
2444 0x813f3978f8940984, 0x4000000000000000,
2445 0xa18f07d736b90be5, 0x5000000000000000,
2446 0xc9f2c9cd04674ede, 0xa400000000000000,
2447 0xfc6f7c4045812296, 0x4d00000000000000,
2448 0x9dc5ada82b70b59d, 0xf020000000000000,
2449 0xc5371912364ce305, 0x6c28000000000000,
2450 0xf684df56c3e01bc6, 0xc732000000000000,
2451 0x9a130b963a6c115c, 0x3c7f400000000000,
2452 0xc097ce7bc90715b3, 0x4b9f100000000000,
2453 0xf0bdc21abb48db20, 0x1e86d40000000000,
2454 0x96769950b50d88f4, 0x1314448000000000,
2455 0xbc143fa4e250eb31, 0x17d955a000000000,
2456 0xeb194f8e1ae525fd, 0x5dcfab0800000000,
2457 0x92efd1b8d0cf37be, 0x5aa1cae500000000,
2458 0xb7abc627050305ad, 0xf14a3d9e40000000,
2459 0xe596b7b0c643c719, 0x6d9ccd05d0000000,
2460 0x8f7e32ce7bea5c6f, 0xe4820023a2000000,
2461 0xb35dbf821ae4f38b, 0xdda2802c8a800000,
2462 0xe0352f62a19e306e, 0xd50b2037ad200000,
2463 0x8c213d9da502de45, 0x4526f422cc340000,
2464 0xaf298d050e4395d6, 0x9670b12b7f410000,
2465 0xdaf3f04651d47b4c, 0x3c0cdd765f114000,
2466 0x88d8762bf324cd0f, 0xa5880a69fb6ac800,
2467 0xab0e93b6efee0053, 0x8eea0d047a457a00,
2468 0xd5d238a4abe98068, 0x72a4904598d6d880,
2469 0x85a36366eb71f041, 0x47a6da2b7f864750,
2470 0xa70c3c40a64e6c51, 0x999090b65f67d924,
2471 0xd0cf4b50cfe20765, 0xfff4b4e3f741cf6d,
2472 0x82818f1281ed449f, 0xbff8f10e7a8921a4,
2473 0xa321f2d7226895c7, 0xaff72d52192b6a0d,
2474 0xcbea6f8ceb02bb39, 0x9bf4f8a69f764490,
2475 0xfee50b7025c36a08, 0x2f236d04753d5b4,
2476 0x9f4f2726179a2245, 0x1d762422c946590,
2477 0xc722f0ef9d80aad6, 0x424d3ad2b7b97ef5,
2478 0xf8ebad2b84e0d58b, 0xd2e0898765a7deb2,
2479 0x9b934c3b330c8577, 0x63cc55f49f88eb2f,
2480 0xc2781f49ffcfa6d5, 0x3cbf6b71c76b25fb,
2481 0xf316271c7fc3908a, 0x8bef464e3945ef7a,
2482 0x97edd871cfda3a56, 0x97758bf0e3cbb5ac,
2483 0xbde94e8e43d0c8ec, 0x3d52eeed1cbea317,
2484 0xed63a231d4c4fb27, 0x4ca7aaa863ee4bdd,
2485 0x945e455f24fb1cf8, 0x8fe8caa93e74ef6a,
2486 0xb975d6b6ee39e436, 0xb3e2fd538e122b44,
2487 0xe7d34c64a9c85d44, 0x60dbbca87196b616,
2488 0x90e40fbeea1d3a4a, 0xbc8955e946fe31cd,
2489 0xb51d13aea4a488dd, 0x6babab6398bdbe41,
2490 0xe264589a4dcdab14, 0xc696963c7eed2dd1,
2491 0x8d7eb76070a08aec, 0xfc1e1de5cf543ca2,
2492 0xb0de65388cc8ada8, 0x3b25a55f43294bcb,
2493 0xdd15fe86affad912, 0x49ef0eb713f39ebe,
2494 0x8a2dbf142dfcc7ab, 0x6e3569326c784337,
2495 0xacb92ed9397bf996, 0x49c2c37f07965404,
2496 0xd7e77a8f87daf7fb, 0xdc33745ec97be906,
2497 0x86f0ac99b4e8dafd, 0x69a028bb3ded71a3,
2498 0xa8acd7c0222311bc, 0xc40832ea0d68ce0c,
2499 0xd2d80db02aabd62b, 0xf50a3fa490c30190,
2500 0x83c7088e1aab65db, 0x792667c6da79e0fa,
2501 0xa4b8cab1a1563f52, 0x577001b891185938,
2502 0xcde6fd5e09abcf26, 0xed4c0226b55e6f86,
2503 0x80b05e5ac60b6178, 0x544f8158315b05b4,
2504 0xa0dc75f1778e39d6, 0x696361ae3db1c721,
2505 0xc913936dd571c84c, 0x3bc3a19cd1e38e9,
2506 0xfb5878494ace3a5f, 0x4ab48a04065c723,
2507 0x9d174b2dcec0e47b, 0x62eb0d64283f9c76,
2508 0xc45d1df942711d9a, 0x3ba5d0bd324f8394,
2509 0xf5746577930d6500, 0xca8f44ec7ee36479,
2510 0x9968bf6abbe85f20, 0x7e998b13cf4e1ecb,
2511 0xbfc2ef456ae276e8, 0x9e3fedd8c321a67e,
2512 0xefb3ab16c59b14a2, 0xc5cfe94ef3ea101e,
2513 0x95d04aee3b80ece5, 0xbba1f1d158724a12,
2514 0xbb445da9ca61281f, 0x2a8a6e45ae8edc97,
2515 0xea1575143cf97226, 0xf52d09d71a3293bd,
2516 0x924d692ca61be758, 0x593c2626705f9c56,
2517 0xb6e0c377cfa2e12e, 0x6f8b2fb00c77836c,
2518 0xe498f455c38b997a, 0xb6dfb9c0f956447,
2519 0x8edf98b59a373fec, 0x4724bd4189bd5eac,
2520 0xb2977ee300c50fe7, 0x58edec91ec2cb657,
2521 0xdf3d5e9bc0f653e1, 0x2f2967b66737e3ed,
2522 0x8b865b215899f46c, 0xbd79e0d20082ee74,
2523 0xae67f1e9aec07187, 0xecd8590680a3aa11,
2524 0xda01ee641a708de9, 0xe80e6f4820cc9495,
2525 0x884134fe908658b2, 0x3109058d147fdcdd,
2526 0xaa51823e34a7eede, 0xbd4b46f0599fd415,
2527 0xd4e5e2cdc1d1ea96, 0x6c9e18ac7007c91a,
2528 0x850fadc09923329e, 0x3e2cf6bc604ddb0,
2529 0xa6539930bf6bff45, 0x84db8346b786151c,
2530 0xcfe87f7cef46ff16, 0xe612641865679a63,
2531 0x81f14fae158c5f6e, 0x4fcb7e8f3f60c07e,
2532 0xa26da3999aef7749, 0xe3be5e330f38f09d,
2533 0xcb090c8001ab551c, 0x5cadf5bfd3072cc5,
2534 0xfdcb4fa002162a63, 0x73d9732fc7c8f7f6,
2535 0x9e9f11c4014dda7e, 0x2867e7fddcdd9afa,
2536 0xc646d63501a1511d, 0xb281e1fd541501b8,
2537 0xf7d88bc24209a565, 0x1f225a7ca91a4226,
2538 0x9ae757596946075f, 0x3375788de9b06958,
2539 0xc1a12d2fc3978937, 0x52d6b1641c83ae,
2540 0xf209787bb47d6b84, 0xc0678c5dbd23a49a,
2541 0x9745eb4d50ce6332, 0xf840b7ba963646e0,
2542 0xbd176620a501fbff, 0xb650e5a93bc3d898,
2543 0xec5d3fa8ce427aff, 0xa3e51f138ab4cebe,
2544 0x93ba47c980e98cdf, 0xc66f336c36b10137,
2545 0xb8a8d9bbe123f017, 0xb80b0047445d4184,
2546 0xe6d3102ad96cec1d, 0xa60dc059157491e5,
2547 0x9043ea1ac7e41392, 0x87c89837ad68db2f,
2548 0xb454e4a179dd1877, 0x29babe4598c311fb,
2549 0xe16a1dc9d8545e94, 0xf4296dd6fef3d67a,
2550 0x8ce2529e2734bb1d, 0x1899e4a65f58660c,
2551 0xb01ae745b101e9e4, 0x5ec05dcff72e7f8f,
2552 0xdc21a1171d42645d, 0x76707543f4fa1f73,
2553 0x899504ae72497eba, 0x6a06494a791c53a8,
2554 0xabfa45da0edbde69, 0x487db9d17636892,
2555 0xd6f8d7509292d603, 0x45a9d2845d3c42b6,
2556 0x865b86925b9bc5c2, 0xb8a2392ba45a9b2,
2557 0xa7f26836f282b732, 0x8e6cac7768d7141e,
2558 0xd1ef0244af2364ff, 0x3207d795430cd926,
2559 0x8335616aed761f1f, 0x7f44e6bd49e807b8,
2560 0xa402b9c5a8d3a6e7, 0x5f16206c9c6209a6,
2561 0xcd036837130890a1, 0x36dba887c37a8c0f,
2562 0x802221226be55a64, 0xc2494954da2c9789,
2563 0xa02aa96b06deb0fd, 0xf2db9baa10b7bd6c,
2564 0xc83553c5c8965d3d, 0x6f92829494e5acc7,
2565 0xfa42a8b73abbf48c, 0xcb772339ba1f17f9,
2566 0x9c69a97284b578d7, 0xff2a760414536efb,
2567 0xc38413cf25e2d70d, 0xfef5138519684aba,
2568 0xf46518c2ef5b8cd1, 0x7eb258665fc25d69,
2569 0x98bf2f79d5993802, 0xef2f773ffbd97a61,
2570 0xbeeefb584aff8603, 0xaafb550ffacfd8fa,
2571 0xeeaaba2e5dbf6784, 0x95ba2a53f983cf38,
2572 0x952ab45cfa97a0b2, 0xdd945a747bf26183,
2573 0xba756174393d88df, 0x94f971119aeef9e4,
2574 0xe912b9d1478ceb17, 0x7a37cd5601aab85d,
2575 0x91abb422ccb812ee, 0xac62e055c10ab33a,
2576 0xb616a12b7fe617aa, 0x577b986b314d6009,
2577 0xe39c49765fdf9d94, 0xed5a7e85fda0b80b,
2578 0x8e41ade9fbebc27d, 0x14588f13be847307,
2579 0xb1d219647ae6b31c, 0x596eb2d8ae258fc8,
2580 0xde469fbd99a05fe3, 0x6fca5f8ed9aef3bb,
2581 0x8aec23d680043bee, 0x25de7bb9480d5854,
2582 0xada72ccc20054ae9, 0xaf561aa79a10ae6a,
2583 0xd910f7ff28069da4, 0x1b2ba1518094da04,
2584 0x87aa9aff79042286, 0x90fb44d2f05d0842,
2585 0xa99541bf57452b28, 0x353a1607ac744a53,
2586 0xd3fa922f2d1675f2, 0x42889b8997915ce8,
2587 0x847c9b5d7c2e09b7, 0x69956135febada11,
2588 0xa59bc234db398c25, 0x43fab9837e699095,
2589 0xcf02b2c21207ef2e, 0x94f967e45e03f4bb,
2590 0x8161afb94b44f57d, 0x1d1be0eebac278f5,
2591 0xa1ba1ba79e1632dc, 0x6462d92a69731732,
2592 0xca28a291859bbf93, 0x7d7b8f7503cfdcfe,
2593 0xfcb2cb35e702af78, 0x5cda735244c3d43e,
2594 0x9defbf01b061adab, 0x3a0888136afa64a7,
2595 0xc56baec21c7a1916, 0x88aaa1845b8fdd0,
2596 0xf6c69a72a3989f5b, 0x8aad549e57273d45,
2597 0x9a3c2087a63f6399, 0x36ac54e2f678864b,
2598 0xc0cb28a98fcf3c7f, 0x84576a1bb416a7dd,
2599 0xf0fdf2d3f3c30b9f, 0x656d44a2a11c51d5,
2600 0x969eb7c47859e743, 0x9f644ae5a4b1b325,
2601 0xbc4665b596706114, 0x873d5d9f0dde1fee,
2602 0xeb57ff22fc0c7959, 0xa90cb506d155a7ea,
2603 0x9316ff75dd87cbd8, 0x9a7f12442d588f2,
2604 0xb7dcbf5354e9bece, 0xc11ed6d538aeb2f,
2605 0xe5d3ef282a242e81, 0x8f1668c8a86da5fa,
2606 0x8fa475791a569d10, 0xf96e017d694487bc,
2607 0xb38d92d760ec4455, 0x37c981dcc395a9ac,
2608 0xe070f78d3927556a, 0x85bbe253f47b1417,
2609 0x8c469ab843b89562, 0x93956d7478ccec8e,
2610 0xaf58416654a6babb, 0x387ac8d1970027b2,
2611 0xdb2e51bfe9d0696a, 0x6997b05fcc0319e,
2612 0x88fcf317f22241e2, 0x441fece3bdf81f03,
2613 0xab3c2fddeeaad25a, 0xd527e81cad7626c3,
2614 0xd60b3bd56a5586f1, 0x8a71e223d8d3b074,
2615 0x85c7056562757456, 0xf6872d5667844e49,
2616 0xa738c6bebb12d16c, 0xb428f8ac016561db,
2617 0xd106f86e69d785c7, 0xe13336d701beba52,
2618 0x82a45b450226b39c, 0xecc0024661173473,
2619 0xa34d721642b06084, 0x27f002d7f95d0190,
2620 0xcc20ce9bd35c78a5, 0x31ec038df7b441f4,
2621 0xff290242c83396ce, 0x7e67047175a15271,
2622 0x9f79a169bd203e41, 0xf0062c6e984d386,
2623 0xc75809c42c684dd1, 0x52c07b78a3e60868,
2624 0xf92e0c3537826145, 0xa7709a56ccdf8a82,
2625 0x9bbcc7a142b17ccb, 0x88a66076400bb691,
2626 0xc2abf989935ddbfe, 0x6acff893d00ea435,
2627 0xf356f7ebf83552fe, 0x583f6b8c4124d43,
2628 0x98165af37b2153de, 0xc3727a337a8b704a,
2629 0xbe1bf1b059e9a8d6, 0x744f18c0592e4c5c,
2630 0xeda2ee1c7064130c, 0x1162def06f79df73,
2631 0x9485d4d1c63e8be7, 0x8addcb5645ac2ba8,
2632 0xb9a74a0637ce2ee1, 0x6d953e2bd7173692,
2633 0xe8111c87c5c1ba99, 0xc8fa8db6ccdd0437,
2634 0x910ab1d4db9914a0, 0x1d9c9892400a22a2,
2635 0xb54d5e4a127f59c8, 0x2503beb6d00cab4b,
2636 0xe2a0b5dc971f303a, 0x2e44ae64840fd61d,
2637 0x8da471a9de737e24, 0x5ceaecfed289e5d2,
2638 0xb10d8e1456105dad, 0x7425a83e872c5f47,
2639 0xdd50f1996b947518, 0xd12f124e28f77719,
2640 0x8a5296ffe33cc92f, 0x82bd6b70d99aaa6f,
2641 0xace73cbfdc0bfb7b, 0x636cc64d1001550b,
2642 0xd8210befd30efa5a, 0x3c47f7e05401aa4e,
2643 0x8714a775e3e95c78, 0x65acfaec34810a71,
2644 0xa8d9d1535ce3b396, 0x7f1839a741a14d0d,
2645 0xd31045a8341ca07c, 0x1ede48111209a050,
2646 0x83ea2b892091e44d, 0x934aed0aab460432,
2647 0xa4e4b66b68b65d60, 0xf81da84d5617853f,
2648 0xce1de40642e3f4b9, 0x36251260ab9d668e,
2649 0x80d2ae83e9ce78f3, 0xc1d72b7c6b426019,
2650 0xa1075a24e4421730, 0xb24cf65b8612f81f,
2651 0xc94930ae1d529cfc, 0xdee033f26797b627,
2652 0xfb9b7cd9a4a7443c, 0x169840ef017da3b1,
2653 0x9d412e0806e88aa5, 0x8e1f289560ee864e,
2654 0xc491798a08a2ad4e, 0xf1a6f2bab92a27e2,
2655 0xf5b5d7ec8acb58a2, 0xae10af696774b1db,
2656 0x9991a6f3d6bf1765, 0xacca6da1e0a8ef29,
2657 0xbff610b0cc6edd3f, 0x17fd090a58d32af3,
2658 0xeff394dcff8a948e, 0xddfc4b4cef07f5b0,
2659 0x95f83d0a1fb69cd9, 0x4abdaf101564f98e,
2660 0xbb764c4ca7a4440f, 0x9d6d1ad41abe37f1,
2661 0xea53df5fd18d5513, 0x84c86189216dc5ed,
2662 0x92746b9be2f8552c, 0x32fd3cf5b4e49bb4,
2663 0xb7118682dbb66a77, 0x3fbc8c33221dc2a1,
2664 0xe4d5e82392a40515, 0xfabaf3feaa5334a,
2665 0x8f05b1163ba6832d, 0x29cb4d87f2a7400e,
2666 0xb2c71d5bca9023f8, 0x743e20e9ef511012,
2667 0xdf78e4b2bd342cf6, 0x914da9246b255416,
2668 0x8bab8eefb6409c1a, 0x1ad089b6c2f7548e,
2669 0xae9672aba3d0c320, 0xa184ac2473b529b1,
2670 0xda3c0f568cc4f3e8, 0xc9e5d72d90a2741e,
2671 0x8865899617fb1871, 0x7e2fa67c7a658892,
2672 0xaa7eebfb9df9de8d, 0xddbb901b98feeab7,
2673 0xd51ea6fa85785631, 0x552a74227f3ea565,
2674 0x8533285c936b35de, 0xd53a88958f87275f,
2675 0xa67ff273b8460356, 0x8a892abaf368f137,
2676 0xd01fef10a657842c, 0x2d2b7569b0432d85,
2677 0x8213f56a67f6b29b, 0x9c3b29620e29fc73,
2678 0xa298f2c501f45f42, 0x8349f3ba91b47b8f,
2679 0xcb3f2f7642717713, 0x241c70a936219a73,
2680 0xfe0efb53d30dd4d7, 0xed238cd383aa0110,
2681 0x9ec95d1463e8a506, 0xf4363804324a40aa,
2682 0xc67bb4597ce2ce48, 0xb143c6053edcd0d5,
2683 0xf81aa16fdc1b81da, 0xdd94b7868e94050a,
2684 0x9b10a4e5e9913128, 0xca7cf2b4191c8326,
2685 0xc1d4ce1f63f57d72, 0xfd1c2f611f63a3f0,
2686 0xf24a01a73cf2dccf, 0xbc633b39673c8cec,
2687 0x976e41088617ca01, 0xd5be0503e085d813,
2688 0xbd49d14aa79dbc82, 0x4b2d8644d8a74e18,
2689 0xec9c459d51852ba2, 0xddf8e7d60ed1219e,
2690 0x93e1ab8252f33b45, 0xcabb90e5c942b503,
2691 0xb8da1662e7b00a17, 0x3d6a751f3b936243,
2692 0xe7109bfba19c0c9d, 0xcc512670a783ad4,
2693 0x906a617d450187e2, 0x27fb2b80668b24c5,
2694 0xb484f9dc9641e9da, 0xb1f9f660802dedf6,
2695 0xe1a63853bbd26451, 0x5e7873f8a0396973,
2696 0x8d07e33455637eb2, 0xdb0b487b6423e1e8,
2697 0xb049dc016abc5e5f, 0x91ce1a9a3d2cda62,
2698 0xdc5c5301c56b75f7, 0x7641a140cc7810fb,
2699 0x89b9b3e11b6329ba, 0xa9e904c87fcb0a9d,
2700 0xac2820d9623bf429, 0x546345fa9fbdcd44,
2701 0xd732290fbacaf133, 0xa97c177947ad4095,
2702 0x867f59a9d4bed6c0, 0x49ed8eabcccc485d,
2703 0xa81f301449ee8c70, 0x5c68f256bfff5a74,
2704 0xd226fc195c6a2f8c, 0x73832eec6fff3111,
2705 0x83585d8fd9c25db7, 0xc831fd53c5ff7eab,
2706 0xa42e74f3d032f525, 0xba3e7ca8b77f5e55,
2707 0xcd3a1230c43fb26f, 0x28ce1bd2e55f35eb,
2708 0x80444b5e7aa7cf85, 0x7980d163cf5b81b3,
2709 0xa0555e361951c366, 0xd7e105bcc332621f,
2710 0xc86ab5c39fa63440, 0x8dd9472bf3fefaa7,
2711 0xfa856334878fc150, 0xb14f98f6f0feb951,
2712 0x9c935e00d4b9d8d2, 0x6ed1bf9a569f33d3,
2713 0xc3b8358109e84f07, 0xa862f80ec4700c8,
2714 0xf4a642e14c6262c8, 0xcd27bb612758c0fa,
2715 0x98e7e9cccfbd7dbd, 0x8038d51cb897789c,
2716 0xbf21e44003acdd2c, 0xe0470a63e6bd56c3,
2717 0xeeea5d5004981478, 0x1858ccfce06cac74,
2718 0x95527a5202df0ccb, 0xf37801e0c43ebc8,
2719 0xbaa718e68396cffd, 0xd30560258f54e6ba,
2720 0xe950df20247c83fd, 0x47c6b82ef32a2069,
2721 0x91d28b7416cdd27e, 0x4cdc331d57fa5441,
2722 0xb6472e511c81471d, 0xe0133fe4adf8e952,
2723 0xe3d8f9e563a198e5, 0x58180fddd97723a6,
2724 0x8e679c2f5e44ff8f, 0x570f09eaa7ea7648,
2725 };
2726};
2727
2728#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
2729
2730template <class unused>
2731constexpr uint64_t
2732 powers_template<unused>::power_of_five_128[number_of_entries];
2733
2734#endif
2735
2736using powers = powers_template<>;
2737
2738} // namespace fast_float
2739
2740#endif
2741
2742#ifndef FASTFLOAT_DECIMAL_TO_BINARY_H
2743#define FASTFLOAT_DECIMAL_TO_BINARY_H
2744
2745#include <cfloat>
2746#include <cinttypes>
2747#include <cmath>
2748#include <cstdint>
2749#include <cstdlib>
2750#include <cstring>
2751
2752namespace fast_float {
2753
2754// This will compute or rather approximate w * 5**q and return a pair of 64-bit
2755// words approximating the result, with the "high" part corresponding to the
2756// most significant bits and the low part corresponding to the least significant
2757// bits.
2758//
2759template <int bit_precision>
2760fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
2761compute_product_approximation(int64_t q, uint64_t w) {
2762 int const index = 2 * int(q - powers::smallest_power_of_five);
2763 // For small values of q, e.g., q in [0,27], the answer is always exact
2764 // because The line value128 firstproduct = full_multiplication(w,
2765 // power_of_five_128[index]); gives the exact answer.
2766 value128 firstproduct =
2767 full_multiplication(w, powers::power_of_five_128[index]);
2768 static_assert((bit_precision >= 0) && (bit_precision <= 64),
2769 " precision should be in (0,64]");
2770 constexpr uint64_t precision_mask =
2771 (bit_precision < 64) ? (uint64_t(0xFFFFFFFFFFFFFFFF) >> bit_precision)
2772 : uint64_t(0xFFFFFFFFFFFFFFFF);
2773 if ((firstproduct.high & precision_mask) ==
2774 precision_mask) { // could further guard with (lower + w < lower)
2775 // regarding the second product, we only need secondproduct.high, but our
2776 // expectation is that the compiler will optimize this extra work away if
2777 // needed.
2778 value128 secondproduct =
2779 full_multiplication(w, powers::power_of_five_128[index + 1]);
2780 firstproduct.low += secondproduct.high;
2781 if (secondproduct.high > firstproduct.low) {
2782 firstproduct.high++;
2783 }
2784 }
2785 return firstproduct;
2786}
2787
2788namespace detail {
2804constexpr fastfloat_really_inline int32_t power(int32_t q) noexcept {
2805 return (((152170 + 65536) * q) >> 16) + 63;
2806}
2807} // namespace detail
2808
2809// create an adjusted mantissa, biased by the invalid power2
2810// for significant digits already multiplied by 10 ** q.
2811template <typename binary>
2812fastfloat_really_inline FASTFLOAT_CONSTEXPR14 adjusted_mantissa
2813compute_error_scaled(int64_t q, uint64_t w, int lz) noexcept {
2814 int hilz = int(w >> 63) ^ 1;
2815 adjusted_mantissa answer;
2816 answer.mantissa = w << hilz;
2817 int bias = binary::mantissa_explicit_bits() - binary::minimum_exponent();
2818 answer.power2 = int32_t(detail::power(int32_t(q)) + bias - hilz - lz - 62 +
2819 invalid_am_bias);
2820 return answer;
2821}
2822
2823// w * 10 ** q, without rounding the representation up.
2824// the power2 in the exponent will be adjusted by invalid_am_bias.
2825template <typename binary>
2826fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
2827compute_error(int64_t q, uint64_t w) noexcept {
2828 int lz = leading_zeroes(w);
2829 w <<= lz;
2830 value128 product =
2831 compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
2832 return compute_error_scaled<binary>(q, product.high, lz);
2833}
2834
2835// Computers w * 10 ** q.
2836// The returned value should be a valid number that simply needs to be
2837// packed. However, in some very rare cases, the computation will fail. In such
2838// cases, we return an adjusted_mantissa with a negative power of 2: the caller
2839// should recompute in such cases.
2840template <typename binary>
2841fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
2842compute_float(int64_t q, uint64_t w) noexcept {
2843 adjusted_mantissa answer;
2844 if ((w == 0) || (q < binary::smallest_power_of_ten())) {
2845 answer.power2 = 0;
2846 answer.mantissa = 0;
2847 // result should be zero
2848 return answer;
2849 }
2850 if (q > binary::largest_power_of_ten()) {
2851 // we want to get infinity:
2852 answer.power2 = binary::infinite_power();
2853 answer.mantissa = 0;
2854 return answer;
2855 }
2856 // At this point in time q is in [powers::smallest_power_of_five,
2857 // powers::largest_power_of_five].
2858
2859 // We want the most significant bit of i to be 1. Shift if needed.
2860 int lz = leading_zeroes(w);
2861 w <<= lz;
2862
2863 // The required precision is binary::mantissa_explicit_bits() + 3 because
2864 // 1. We need the implicit bit
2865 // 2. We need an extra bit for rounding purposes
2866 // 3. We might lose a bit due to the "upperbit" routine (result too small,
2867 // requiring a shift)
2868
2869 value128 product =
2870 compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
2871 // The computed 'product' is always sufficient.
2872 // Mathematical proof:
2873 // Noble Mushtak and Daniel Lemire, Fast Number Parsing Without Fallback (to
2874 // appear) See script/mushtak_lemire.py
2875
2876 // The "compute_product_approximation" function can be slightly slower than a
2877 // branchless approach: value128 product = compute_product(q, w); but in
2878 // practice, we can win big with the compute_product_approximation if its
2879 // additional branch is easily predicted. Which is best is data specific.
2880 int upperbit = int(product.high >> 63);
2881 int shift = upperbit + 64 - binary::mantissa_explicit_bits() - 3;
2882
2883 answer.mantissa = product.high >> shift;
2884
2885 answer.power2 = int32_t(detail::power(int32_t(q)) + upperbit - lz -
2886 binary::minimum_exponent());
2887 if (answer.power2 <= 0) { // we have a subnormal?
2888 // Here have that answer.power2 <= 0 so -answer.power2 >= 0
2889 if (-answer.power2 + 1 >=
2890 64) { // if we have more than 64 bits below the minimum exponent, you
2891 // have a zero for sure.
2892 answer.power2 = 0;
2893 answer.mantissa = 0;
2894 // result should be zero
2895 return answer;
2896 }
2897 // next line is safe because -answer.power2 + 1 < 64
2898 answer.mantissa >>= -answer.power2 + 1;
2899 // Thankfully, we can't have both "round-to-even" and subnormals because
2900 // "round-to-even" only occurs for powers close to 0 in the 32-bit and
2901 // and 64-bit case (with no more than 19 digits).
2902 answer.mantissa += (answer.mantissa & 1); // round up
2903 answer.mantissa >>= 1;
2904 // There is a weird scenario where we don't have a subnormal but just.
2905 // Suppose we start with 2.2250738585072013e-308, we end up
2906 // with 0x3fffffffffffff x 2^-1023-53 which is technically subnormal
2907 // whereas 0x40000000000000 x 2^-1023-53 is normal. Now, we need to round
2908 // up 0x3fffffffffffff x 2^-1023-53 and once we do, we are no longer
2909 // subnormal, but we can only know this after rounding.
2910 // So we only declare a subnormal if we are smaller than the threshold.
2911 answer.power2 =
2912 (answer.mantissa < (uint64_t(1) << binary::mantissa_explicit_bits()))
2913 ? 0
2914 : 1;
2915 return answer;
2916 }
2917
2918 // usually, we round *up*, but if we fall right in between and and we have an
2919 // even basis, we need to round down
2920 // We are only concerned with the cases where 5**q fits in single 64-bit word.
2921 if ((product.low <= 1) && (q >= binary::min_exponent_round_to_even()) &&
2922 (q <= binary::max_exponent_round_to_even()) &&
2923 ((answer.mantissa & 3) == 1)) { // we may fall between two floats!
2924 // To be in-between two floats we need that in doing
2925 // answer.mantissa = product.high >> (upperbit + 64 -
2926 // binary::mantissa_explicit_bits() - 3);
2927 // ... we dropped out only zeroes. But if this happened, then we can go
2928 // back!!!
2929 if ((answer.mantissa << shift) == product.high) {
2930 answer.mantissa &= ~uint64_t(1); // flip it so that we do not round up
2931 }
2932 }
2933
2934 answer.mantissa += (answer.mantissa & 1); // round up
2935 answer.mantissa >>= 1;
2936 if (answer.mantissa >= (uint64_t(2) << binary::mantissa_explicit_bits())) {
2937 answer.mantissa = (uint64_t(1) << binary::mantissa_explicit_bits());
2938 answer.power2++; // undo previous addition
2939 }
2940
2941 answer.mantissa &= ~(uint64_t(1) << binary::mantissa_explicit_bits());
2942 if (answer.power2 >= binary::infinite_power()) { // infinity
2943 answer.power2 = binary::infinite_power();
2944 answer.mantissa = 0;
2945 }
2946 return answer;
2947}
2948
2949} // namespace fast_float
2950
2951#endif
2952
2953#ifndef FASTFLOAT_BIGINT_H
2954#define FASTFLOAT_BIGINT_H
2955
2956#include <algorithm>
2957#include <cstdint>
2958#include <climits>
2959#include <cstring>
2960
2961
2962namespace fast_float {
2963
2964// the limb width: we want efficient multiplication of double the bits in
2965// limb, or for 64-bit limbs, at least 64-bit multiplication where we can
2966// extract the high and low parts efficiently. this is every 64-bit
2967// architecture except for sparc, which emulates 128-bit multiplication.
2968// we might have platforms where `CHAR_BIT` is not 8, so let's avoid
2969// doing `8 * sizeof(limb)`.
2970#if defined(FASTFLOAT_64BIT) && !defined(__sparc)
2971#define FASTFLOAT_64BIT_LIMB 1
2972typedef uint64_t limb;
2973constexpr size_t limb_bits = 64;
2974#else
2975#define FASTFLOAT_32BIT_LIMB
2976typedef uint32_t limb;
2977constexpr size_t limb_bits = 32;
2978#endif
2979
2980typedef span<limb> limb_span;
2981
2982// number of bits in a bigint. this needs to be at least the number
2983// of bits required to store the largest bigint, which is
2984// `log2(10**(digits + max_exp))`, or `log2(10**(767 + 342))`, or
2985// ~3600 bits, so we round to 4000.
2986constexpr size_t bigint_bits = 4000;
2987constexpr size_t bigint_limbs = bigint_bits / limb_bits;
2988
2989// vector-like type that is allocated on the stack. the entire
2990// buffer is pre-allocated, and only the length changes.
2991template <uint16_t size> struct stackvec {
2992 limb data[size];
2993 // we never need more than 150 limbs
2994 uint16_t length{0};
2995
2996 stackvec() = default;
2997 stackvec(stackvec const &) = delete;
2998 stackvec &operator=(stackvec const &) = delete;
2999 stackvec(stackvec &&) = delete;
3000 stackvec &operator=(stackvec &&other) = delete;
3001
3002 // create stack vector from existing limb span.
3003 FASTFLOAT_CONSTEXPR20 stackvec(limb_span s) {
3004 FASTFLOAT_ASSERT(try_extend(s));
3005 }
3006
3007 FASTFLOAT_CONSTEXPR14 limb &operator[](size_t index) noexcept {
3008 FASTFLOAT_DEBUG_ASSERT(index < length);
3009 return data[index];
3010 }
3011
3012 FASTFLOAT_CONSTEXPR14 const limb &operator[](size_t index) const noexcept {
3013 FASTFLOAT_DEBUG_ASSERT(index < length);
3014 return data[index];
3015 }
3016
3017 // index from the end of the container
3018 FASTFLOAT_CONSTEXPR14 const limb &rindex(size_t index) const noexcept {
3019 FASTFLOAT_DEBUG_ASSERT(index < length);
3020 size_t rindex = length - index - 1;
3021 return data[rindex];
3022 }
3023
3024 // set the length, without bounds checking.
3025 FASTFLOAT_CONSTEXPR14 void set_len(size_t len) noexcept {
3026 length = uint16_t(len);
3027 }
3028
3029 constexpr size_t len() const noexcept { return length; }
3030
3031 constexpr bool is_empty() const noexcept { return length == 0; }
3032
3033 constexpr size_t capacity() const noexcept { return size; }
3034
3035 // append item to vector, without bounds checking
3036 FASTFLOAT_CONSTEXPR14 void push_unchecked(limb value) noexcept {
3037 data[length] = value;
3038 length++;
3039 }
3040
3041 // append item to vector, returning if item was added
3042 FASTFLOAT_CONSTEXPR14 bool try_push(limb value) noexcept {
3043 if (len() < capacity()) {
3044 push_unchecked(value);
3045 return true;
3046 } else {
3047 return false;
3048 }
3049 }
3050
3051 // add items to the vector, from a span, without bounds checking
3052 FASTFLOAT_CONSTEXPR20 void extend_unchecked(limb_span s) noexcept {
3053 limb *ptr = data + length;
3054 std::copy_n(s.ptr, s.len(), ptr);
3055 set_len(len() + s.len());
3056 }
3057
3058 // try to add items to the vector, returning if items were added
3059 FASTFLOAT_CONSTEXPR20 bool try_extend(limb_span s) noexcept {
3060 if (len() + s.len() <= capacity()) {
3061 extend_unchecked(s);
3062 return true;
3063 } else {
3064 return false;
3065 }
3066 }
3067
3068 // resize the vector, without bounds checking
3069 // if the new size is longer than the vector, assign value to each
3070 // appended item.
3071 FASTFLOAT_CONSTEXPR20
3072 void resize_unchecked(size_t new_len, limb value) noexcept {
3073 if (new_len > len()) {
3074 size_t count = new_len - len();
3075 limb *first = data + len();
3076 limb *last = first + count;
3077 ::std::fill(first, last, value);
3078 set_len(new_len);
3079 } else {
3080 set_len(new_len);
3081 }
3082 }
3083
3084 // try to resize the vector, returning if the vector was resized.
3085 FASTFLOAT_CONSTEXPR20 bool try_resize(size_t new_len, limb value) noexcept {
3086 if (new_len > capacity()) {
3087 return false;
3088 } else {
3089 resize_unchecked(new_len, value);
3090 return true;
3091 }
3092 }
3093
3094 // check if any limbs are non-zero after the given index.
3095 // this needs to be done in reverse order, since the index
3096 // is relative to the most significant limbs.
3097 FASTFLOAT_CONSTEXPR14 bool nonzero(size_t index) const noexcept {
3098 while (index < len()) {
3099 if (rindex(index) != 0) {
3100 return true;
3101 }
3102 index++;
3103 }
3104 return false;
3105 }
3106
3107 // normalize the big integer, so most-significant zero limbs are removed.
3108 FASTFLOAT_CONSTEXPR14 void normalize() noexcept {
3109 while (len() > 0 && rindex(0) == 0) {
3110 length--;
3111 }
3112 }
3113};
3114
3115fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint64_t
3116empty_hi64(bool &truncated) noexcept {
3117 truncated = false;
3118 return 0;
3119}
3120
3121fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
3122uint64_hi64(uint64_t r0, bool &truncated) noexcept {
3123 truncated = false;
3124 int shl = leading_zeroes(r0);
3125 return r0 << shl;
3126}
3127
3128fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
3129uint64_hi64(uint64_t r0, uint64_t r1, bool &truncated) noexcept {
3130 int shl = leading_zeroes(r0);
3131 if (shl == 0) {
3132 truncated = r1 != 0;
3133 return r0;
3134 } else {
3135 int shr = 64 - shl;
3136 truncated = (r1 << shl) != 0;
3137 return (r0 << shl) | (r1 >> shr);
3138 }
3139}
3140
3141fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
3142uint32_hi64(uint32_t r0, bool &truncated) noexcept {
3143 return uint64_hi64(r0, truncated);
3144}
3145
3146fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
3147uint32_hi64(uint32_t r0, uint32_t r1, bool &truncated) noexcept {
3148 uint64_t x0 = r0;
3149 uint64_t x1 = r1;
3150 return uint64_hi64((x0 << 32) | x1, truncated);
3151}
3152
3153fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
3154uint32_hi64(uint32_t r0, uint32_t r1, uint32_t r2, bool &truncated) noexcept {
3155 uint64_t x0 = r0;
3156 uint64_t x1 = r1;
3157 uint64_t x2 = r2;
3158 return uint64_hi64(x0, (x1 << 32) | x2, truncated);
3159}
3160
3161// add two small integers, checking for overflow.
3162// we want an efficient operation. for msvc, where
3163// we don't have built-in intrinsics, this is still
3164// pretty fast.
3165fastfloat_really_inline FASTFLOAT_CONSTEXPR20 limb
3166scalar_add(limb x, limb y, bool &overflow) noexcept {
3167 limb z;
3168// gcc and clang
3169#if defined(__has_builtin)
3170#if __has_builtin(__builtin_add_overflow)
3171 if (!cpp20_and_in_constexpr()) {
3172 overflow = __builtin_add_overflow(x, y, &z);
3173 return z;
3174 }
3175#endif
3176#endif
3177
3178 // generic, this still optimizes correctly on MSVC.
3179 z = x + y;
3180 overflow = z < x;
3181 return z;
3182}
3183
3184// multiply two small integers, getting both the high and low bits.
3185fastfloat_really_inline FASTFLOAT_CONSTEXPR20 limb
3186scalar_mul(limb x, limb y, limb &carry) noexcept {
3187#ifdef FASTFLOAT_64BIT_LIMB
3188#if defined(__SIZEOF_INT128__)
3189 // GCC and clang both define it as an extension.
3190 __uint128_t z = __uint128_t(x) * __uint128_t(y) + __uint128_t(carry);
3191 carry = limb(z >> limb_bits);
3192 return limb(z);
3193#else
3194 // fallback, no native 128-bit integer multiplication with carry.
3195 // on msvc, this optimizes identically, somehow.
3196 value128 z = full_multiplication(x, y);
3197 bool overflow;
3198 z.low = scalar_add(z.low, carry, overflow);
3199 z.high += uint64_t(overflow); // cannot overflow
3200 carry = z.high;
3201 return z.low;
3202#endif
3203#else
3204 uint64_t z = uint64_t(x) * uint64_t(y) + uint64_t(carry);
3205 carry = limb(z >> limb_bits);
3206 return limb(z);
3207#endif
3208}
3209
3210// add scalar value to bigint starting from offset.
3211// used in grade school multiplication
3212template <uint16_t size>
3213inline FASTFLOAT_CONSTEXPR20 bool small_add_from(stackvec<size> &vec, limb y,
3214 size_t start) noexcept {
3215 size_t index = start;
3216 limb carry = y;
3217 bool overflow;
3218 while (carry != 0 && index < vec.len()) {
3219 vec[index] = scalar_add(vec[index], carry, overflow);
3220 carry = limb(overflow);
3221 index += 1;
3222 }
3223 if (carry != 0) {
3224 FASTFLOAT_TRY(vec.try_push(carry));
3225 }
3226 return true;
3227}
3228
3229// add scalar value to bigint.
3230template <uint16_t size>
3231fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool
3232small_add(stackvec<size> &vec, limb y) noexcept {
3233 return small_add_from(vec, y, 0);
3234}
3235
3236// multiply bigint by scalar value.
3237template <uint16_t size>
3238inline FASTFLOAT_CONSTEXPR20 bool small_mul(stackvec<size> &vec,
3239 limb y) noexcept {
3240 limb carry = 0;
3241 for (size_t index = 0; index < vec.len(); index++) {
3242 vec[index] = scalar_mul(vec[index], y, carry);
3243 }
3244 if (carry != 0) {
3245 FASTFLOAT_TRY(vec.try_push(carry));
3246 }
3247 return true;
3248}
3249
3250// add bigint to bigint starting from index.
3251// used in grade school multiplication
3252template <uint16_t size>
3253FASTFLOAT_CONSTEXPR20 bool large_add_from(stackvec<size> &x, limb_span y,
3254 size_t start) noexcept {
3255 // the effective x buffer is from `xstart..x.len()`, so exit early
3256 // if we can't get that current range.
3257 if (x.len() < start || y.len() > x.len() - start) {
3258 FASTFLOAT_TRY(x.try_resize(y.len() + start, 0));
3259 }
3260
3261 bool carry = false;
3262 for (size_t index = 0; index < y.len(); index++) {
3263 limb xi = x[index + start];
3264 limb yi = y[index];
3265 bool c1 = false;
3266 bool c2 = false;
3267 xi = scalar_add(xi, yi, c1);
3268 if (carry) {
3269 xi = scalar_add(xi, 1, c2);
3270 }
3271 x[index + start] = xi;
3272 carry = c1 | c2;
3273 }
3274
3275 // handle overflow
3276 if (carry) {
3277 FASTFLOAT_TRY(small_add_from(x, 1, y.len() + start));
3278 }
3279 return true;
3280}
3281
3282// add bigint to bigint.
3283template <uint16_t size>
3284fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool
3285large_add_from(stackvec<size> &x, limb_span y) noexcept {
3286 return large_add_from(x, y, 0);
3287}
3288
3289// grade-school multiplication algorithm
3290template <uint16_t size>
3291FASTFLOAT_CONSTEXPR20 bool long_mul(stackvec<size> &x, limb_span y) noexcept {
3292 limb_span xs = limb_span(x.data, x.len());
3293 stackvec<size> z(xs);
3294 limb_span zs = limb_span(z.data, z.len());
3295
3296 if (y.len() != 0) {
3297 limb y0 = y[0];
3298 FASTFLOAT_TRY(small_mul(x, y0));
3299 for (size_t index = 1; index < y.len(); index++) {
3300 limb yi = y[index];
3301 stackvec<size> zi;
3302 if (yi != 0) {
3303 // re-use the same buffer throughout
3304 zi.set_len(0);
3305 FASTFLOAT_TRY(zi.try_extend(zs));
3306 FASTFLOAT_TRY(small_mul(zi, yi));
3307 limb_span zis = limb_span(zi.data, zi.len());
3308 FASTFLOAT_TRY(large_add_from(x, zis, index));
3309 }
3310 }
3311 }
3312
3313 x.normalize();
3314 return true;
3315}
3316
3317// grade-school multiplication algorithm
3318template <uint16_t size>
3319FASTFLOAT_CONSTEXPR20 bool large_mul(stackvec<size> &x, limb_span y) noexcept {
3320 if (y.len() == 1) {
3321 FASTFLOAT_TRY(small_mul(x, y[0]));
3322 } else {
3323 FASTFLOAT_TRY(long_mul(x, y));
3324 }
3325 return true;
3326}
3327
3328template <typename = void> struct pow5_tables {
3329 static constexpr uint32_t large_step = 135;
3330 static constexpr uint64_t small_power_of_5[] = {
3331 1UL,
3332 5UL,
3333 25UL,
3334 125UL,
3335 625UL,
3336 3125UL,
3337 15625UL,
3338 78125UL,
3339 390625UL,
3340 1953125UL,
3341 9765625UL,
3342 48828125UL,
3343 244140625UL,
3344 1220703125UL,
3345 6103515625UL,
3346 30517578125UL,
3347 152587890625UL,
3348 762939453125UL,
3349 3814697265625UL,
3350 19073486328125UL,
3351 95367431640625UL,
3352 476837158203125UL,
3353 2384185791015625UL,
3354 11920928955078125UL,
3355 59604644775390625UL,
3356 298023223876953125UL,
3357 1490116119384765625UL,
3358 7450580596923828125UL,
3359 };
3360#ifdef FASTFLOAT_64BIT_LIMB
3361 constexpr static limb large_power_of_5[] = {
3362 1414648277510068013UL, 9180637584431281687UL, 4539964771860779200UL,
3363 10482974169319127550UL, 198276706040285095UL};
3364#else
3365 constexpr static limb large_power_of_5[] = {
3366 4279965485U, 329373468U, 4020270615U, 2137533757U, 4287402176U,
3367 1057042919U, 1071430142U, 2440757623U, 381945767U, 46164893U};
3368#endif
3369};
3370
3371#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
3372
3373template <typename T> constexpr uint32_t pow5_tables<T>::large_step;
3374
3375template <typename T> constexpr uint64_t pow5_tables<T>::small_power_of_5[];
3376
3377template <typename T> constexpr limb pow5_tables<T>::large_power_of_5[];
3378
3379#endif
3380
3381// big integer type. implements a small subset of big integer
3382// arithmetic, using simple algorithms since asymptotically
3383// faster algorithms are slower for a small number of limbs.
3384// all operations assume the big-integer is normalized.
3385struct bigint : pow5_tables<> {
3386 // storage of the limbs, in little-endian order.
3387 stackvec<bigint_limbs> vec;
3388
3389 FASTFLOAT_CONSTEXPR20 bigint() : vec() {}
3390
3391 bigint(bigint const &) = delete;
3392 bigint &operator=(bigint const &) = delete;
3393 bigint(bigint &&) = delete;
3394 bigint &operator=(bigint &&other) = delete;
3395
3396 FASTFLOAT_CONSTEXPR20 bigint(uint64_t value) : vec() {
3397#ifdef FASTFLOAT_64BIT_LIMB
3398 vec.push_unchecked(value);
3399#else
3400 vec.push_unchecked(uint32_t(value));
3401 vec.push_unchecked(uint32_t(value >> 32));
3402#endif
3403 vec.normalize();
3404 }
3405
3406 // get the high 64 bits from the vector, and if bits were truncated.
3407 // this is to get the significant digits for the float.
3408 FASTFLOAT_CONSTEXPR20 uint64_t hi64(bool &truncated) const noexcept {
3409#ifdef FASTFLOAT_64BIT_LIMB
3410 if (vec.len() == 0) {
3411 return empty_hi64(truncated);
3412 } else if (vec.len() == 1) {
3413 return uint64_hi64(vec.rindex(0), truncated);
3414 } else {
3415 uint64_t result = uint64_hi64(vec.rindex(0), vec.rindex(1), truncated);
3416 truncated |= vec.nonzero(2);
3417 return result;
3418 }
3419#else
3420 if (vec.len() == 0) {
3421 return empty_hi64(truncated);
3422 } else if (vec.len() == 1) {
3423 return uint32_hi64(vec.rindex(0), truncated);
3424 } else if (vec.len() == 2) {
3425 return uint32_hi64(vec.rindex(0), vec.rindex(1), truncated);
3426 } else {
3427 uint64_t result =
3428 uint32_hi64(vec.rindex(0), vec.rindex(1), vec.rindex(2), truncated);
3429 truncated |= vec.nonzero(3);
3430 return result;
3431 }
3432#endif
3433 }
3434
3435 // compare two big integers, returning the large value.
3436 // assumes both are normalized. if the return value is
3437 // negative, other is larger, if the return value is
3438 // positive, this is larger, otherwise they are equal.
3439 // the limbs are stored in little-endian order, so we
3440 // must compare the limbs in ever order.
3441 FASTFLOAT_CONSTEXPR20 int compare(bigint const &other) const noexcept {
3442 if (vec.len() > other.vec.len()) {
3443 return 1;
3444 } else if (vec.len() < other.vec.len()) {
3445 return -1;
3446 } else {
3447 for (size_t index = vec.len(); index > 0; index--) {
3448 limb xi = vec[index - 1];
3449 limb yi = other.vec[index - 1];
3450 if (xi > yi) {
3451 return 1;
3452 } else if (xi < yi) {
3453 return -1;
3454 }
3455 }
3456 return 0;
3457 }
3458 }
3459
3460 // shift left each limb n bits, carrying over to the new limb
3461 // returns true if we were able to shift all the digits.
3462 FASTFLOAT_CONSTEXPR20 bool shl_bits(size_t n) noexcept {
3463 // Internally, for each item, we shift left by n, and add the previous
3464 // right shifted limb-bits.
3465 // For example, we transform (for u8) shifted left 2, to:
3466 // b10100100 b01000010
3467 // b10 b10010001 b00001000
3468 FASTFLOAT_DEBUG_ASSERT(n != 0);
3469 FASTFLOAT_DEBUG_ASSERT(n < sizeof(limb) * 8);
3470
3471 size_t shl = n;
3472 size_t shr = limb_bits - shl;
3473 limb prev = 0;
3474 for (size_t index = 0; index < vec.len(); index++) {
3475 limb xi = vec[index];
3476 vec[index] = (xi << shl) | (prev >> shr);
3477 prev = xi;
3478 }
3479
3480 limb carry = prev >> shr;
3481 if (carry != 0) {
3482 return vec.try_push(carry);
3483 }
3484 return true;
3485 }
3486
3487 // move the limbs left by `n` limbs.
3488 FASTFLOAT_CONSTEXPR20 bool shl_limbs(size_t n) noexcept {
3489 FASTFLOAT_DEBUG_ASSERT(n != 0);
3490 if (n + vec.len() > vec.capacity()) {
3491 return false;
3492 } else if (!vec.is_empty()) {
3493 // move limbs
3494 limb *dst = vec.data + n;
3495 limb const *src = vec.data;
3496 std::copy_backward(src, src + vec.len(), dst + vec.len());
3497 // fill in empty limbs
3498 limb *first = vec.data;
3499 limb *last = first + n;
3500 ::std::fill(first, last, 0);
3501 vec.set_len(n + vec.len());
3502 return true;
3503 } else {
3504 return true;
3505 }
3506 }
3507
3508 // move the limbs left by `n` bits.
3509 FASTFLOAT_CONSTEXPR20 bool shl(size_t n) noexcept {
3510 size_t rem = n % limb_bits;
3511 size_t div = n / limb_bits;
3512 if (rem != 0) {
3513 FASTFLOAT_TRY(shl_bits(rem));
3514 }
3515 if (div != 0) {
3516 FASTFLOAT_TRY(shl_limbs(div));
3517 }
3518 return true;
3519 }
3520
3521 // get the number of leading zeros in the bigint.
3522 FASTFLOAT_CONSTEXPR20 int ctlz() const noexcept {
3523 if (vec.is_empty()) {
3524 return 0;
3525 } else {
3526#ifdef FASTFLOAT_64BIT_LIMB
3527 return leading_zeroes(vec.rindex(0));
3528#else
3529 // no use defining a specialized leading_zeroes for a 32-bit type.
3530 uint64_t r0 = vec.rindex(0);
3531 return leading_zeroes(r0 << 32);
3532#endif
3533 }
3534 }
3535
3536 // get the number of bits in the bigint.
3537 FASTFLOAT_CONSTEXPR20 int bit_length() const noexcept {
3538 int lz = ctlz();
3539 return int(limb_bits * vec.len()) - lz;
3540 }
3541
3542 FASTFLOAT_CONSTEXPR20 bool mul(limb y) noexcept { return small_mul(vec, y); }
3543
3544 FASTFLOAT_CONSTEXPR20 bool add(limb y) noexcept { return small_add(vec, y); }
3545
3546 // multiply as if by 2 raised to a power.
3547 FASTFLOAT_CONSTEXPR20 bool pow2(uint32_t exp) noexcept { return shl(exp); }
3548
3549 // multiply as if by 5 raised to a power.
3550 FASTFLOAT_CONSTEXPR20 bool pow5(uint32_t exp) noexcept {
3551 // multiply by a power of 5
3552 size_t large_length = sizeof(large_power_of_5) / sizeof(limb);
3553 limb_span large = limb_span(large_power_of_5, large_length);
3554 while (exp >= large_step) {
3555 FASTFLOAT_TRY(large_mul(vec, large));
3556 exp -= large_step;
3557 }
3558#ifdef FASTFLOAT_64BIT_LIMB
3559 uint32_t small_step = 27;
3560 limb max_native = 7450580596923828125UL;
3561#else
3562 uint32_t small_step = 13;
3563 limb max_native = 1220703125U;
3564#endif
3565 while (exp >= small_step) {
3566 FASTFLOAT_TRY(small_mul(vec, max_native));
3567 exp -= small_step;
3568 }
3569 if (exp != 0) {
3570 // Work around clang bug https://godbolt.org/z/zedh7rrhc
3571 // This is similar to https://github.com/llvm/llvm-project/issues/47746,
3572 // except the workaround described there don't work here
3573 FASTFLOAT_TRY(small_mul(
3574 vec, limb(((void)small_power_of_5[0], small_power_of_5[exp]))));
3575 }
3576
3577 return true;
3578 }
3579
3580 // multiply as if by 10 raised to a power.
3581 FASTFLOAT_CONSTEXPR20 bool pow10(uint32_t exp) noexcept {
3582 FASTFLOAT_TRY(pow5(exp));
3583 return pow2(exp);
3584 }
3585};
3586
3587} // namespace fast_float
3588
3589#endif
3590
3591#ifndef FASTFLOAT_DIGIT_COMPARISON_H
3592#define FASTFLOAT_DIGIT_COMPARISON_H
3593
3594#include <algorithm>
3595#include <cstdint>
3596#include <cstring>
3597#include <iterator>
3598
3599
3600namespace fast_float {
3601
3602// 1e0 to 1e19
3603constexpr static uint64_t powers_of_ten_uint64[] = {1UL,
3604 10UL,
3605 100UL,
3606 1000UL,
3607 10000UL,
3608 100000UL,
3609 1000000UL,
3610 10000000UL,
3611 100000000UL,
3612 1000000000UL,
3613 10000000000UL,
3614 100000000000UL,
3615 1000000000000UL,
3616 10000000000000UL,
3617 100000000000000UL,
3618 1000000000000000UL,
3619 10000000000000000UL,
3620 100000000000000000UL,
3621 1000000000000000000UL,
3622 10000000000000000000UL};
3623
3624// calculate the exponent, in scientific notation, of the number.
3625// this algorithm is not even close to optimized, but it has no practical
3626// effect on performance: in order to have a faster algorithm, we'd need
3627// to slow down performance for faster algorithms, and this is still fast.
3628template <typename UC>
3629fastfloat_really_inline FASTFLOAT_CONSTEXPR14 int32_t
3630scientific_exponent(parsed_number_string_t<UC> &num) noexcept {
3631 uint64_t mantissa = num.mantissa;
3632 int32_t exponent = int32_t(num.exponent);
3633 while (mantissa >= 10000) {
3634 mantissa /= 10000;
3635 exponent += 4;
3636 }
3637 while (mantissa >= 100) {
3638 mantissa /= 100;
3639 exponent += 2;
3640 }
3641 while (mantissa >= 10) {
3642 mantissa /= 10;
3643 exponent += 1;
3644 }
3645 return exponent;
3646}
3647
3648// this converts a native floating-point number to an extended-precision float.
3649template <typename T>
3650fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
3651to_extended(T value) noexcept {
3652 using equiv_uint = equiv_uint_t<T>;
3653 constexpr equiv_uint exponent_mask = binary_format<T>::exponent_mask();
3654 constexpr equiv_uint mantissa_mask = binary_format<T>::mantissa_mask();
3655 constexpr equiv_uint hidden_bit_mask = binary_format<T>::hidden_bit_mask();
3656
3657 adjusted_mantissa am;
3658 int32_t bias = binary_format<T>::mantissa_explicit_bits() -
3659 binary_format<T>::minimum_exponent();
3660 equiv_uint bits;
3661#if FASTFLOAT_HAS_BIT_CAST
3662 bits = std::bit_cast<equiv_uint>(value);
3663#else
3664 ::memcpy(&bits, &value, sizeof(T));
3665#endif
3666 if ((bits & exponent_mask) == 0) {
3667 // denormal
3668 am.power2 = 1 - bias;
3669 am.mantissa = bits & mantissa_mask;
3670 } else {
3671 // normal
3672 am.power2 = int32_t((bits & exponent_mask) >>
3673 binary_format<T>::mantissa_explicit_bits());
3674 am.power2 -= bias;
3675 am.mantissa = (bits & mantissa_mask) | hidden_bit_mask;
3676 }
3677
3678 return am;
3679}
3680
3681// get the extended precision value of the halfway point between b and b+u.
3682// we are given a native float that represents b, so we need to adjust it
3683// halfway between b and b+u.
3684template <typename T>
3685fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
3686to_extended_halfway(T value) noexcept {
3687 adjusted_mantissa am = to_extended(value);
3688 am.mantissa <<= 1;
3689 am.mantissa += 1;
3690 am.power2 -= 1;
3691 return am;
3692}
3693
3694// round an extended-precision float to the nearest machine float.
3695template <typename T, typename callback>
3696fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void round(adjusted_mantissa &am,
3697 callback cb) noexcept {
3698 int32_t mantissa_shift = 64 - binary_format<T>::mantissa_explicit_bits() - 1;
3699 if (-am.power2 >= mantissa_shift) {
3700 // have a denormal float
3701 int32_t shift = -am.power2 + 1;
3702 cb(am, std::min<int32_t>(shift, 64));
3703 // check for round-up: if rounding-nearest carried us to the hidden bit.
3704 am.power2 = (am.mantissa <
3705 (uint64_t(1) << binary_format<T>::mantissa_explicit_bits()))
3706 ? 0
3707 : 1;
3708 return;
3709 }
3710
3711 // have a normal float, use the default shift.
3712 cb(am, mantissa_shift);
3713
3714 // check for carry
3715 if (am.mantissa >=
3716 (uint64_t(2) << binary_format<T>::mantissa_explicit_bits())) {
3717 am.mantissa = (uint64_t(1) << binary_format<T>::mantissa_explicit_bits());
3718 am.power2++;
3719 }
3720
3721 // check for infinite: we could have carried to an infinite power
3722 am.mantissa &= ~(uint64_t(1) << binary_format<T>::mantissa_explicit_bits());
3723 if (am.power2 >= binary_format<T>::infinite_power()) {
3724 am.power2 = binary_format<T>::infinite_power();
3725 am.mantissa = 0;
3726 }
3727}
3728
3729template <typename callback>
3730fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void
3731round_nearest_tie_even(adjusted_mantissa &am, int32_t shift,
3732 callback cb) noexcept {
3733 uint64_t const mask = (shift == 64) ? UINT64_MAX : (uint64_t(1) << shift) - 1;
3734 uint64_t const halfway = (shift == 0) ? 0 : uint64_t(1) << (shift - 1);
3735 uint64_t truncated_bits = am.mantissa & mask;
3736 bool is_above = truncated_bits > halfway;
3737 bool is_halfway = truncated_bits == halfway;
3738
3739 // shift digits into position
3740 if (shift == 64) {
3741 am.mantissa = 0;
3742 } else {
3743 am.mantissa >>= shift;
3744 }
3745 am.power2 += shift;
3746
3747 bool is_odd = (am.mantissa & 1) == 1;
3748 am.mantissa += uint64_t(cb(is_odd, is_halfway, is_above));
3749}
3750
3751fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void
3752round_down(adjusted_mantissa &am, int32_t shift) noexcept {
3753 if (shift == 64) {
3754 am.mantissa = 0;
3755 } else {
3756 am.mantissa >>= shift;
3757 }
3758 am.power2 += shift;
3759}
3760
3761template <typename UC>
3762fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
3763skip_zeros(UC const *&first, UC const *last) noexcept {
3764 uint64_t val;
3765 while (!cpp20_and_in_constexpr() &&
3766 std::distance(first, last) >= int_cmp_len<UC>()) {
3767 ::memcpy(&val, first, sizeof(uint64_t));
3768 if (val != int_cmp_zeros<UC>()) {
3769 break;
3770 }
3771 first += int_cmp_len<UC>();
3772 }
3773 while (first != last) {
3774 if (*first != UC('0')) {
3775 break;
3776 }
3777 first++;
3778 }
3779}
3780
3781// determine if any non-zero digits were truncated.
3782// all characters must be valid digits.
3783template <typename UC>
3784fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool
3785is_truncated(UC const *first, UC const *last) noexcept {
3786 // do 8-bit optimizations, can just compare to 8 literal 0s.
3787 uint64_t val;
3788 while (!cpp20_and_in_constexpr() &&
3789 std::distance(first, last) >= int_cmp_len<UC>()) {
3790 ::memcpy(&val, first, sizeof(uint64_t));
3791 if (val != int_cmp_zeros<UC>()) {
3792 return true;
3793 }
3794 first += int_cmp_len<UC>();
3795 }
3796 while (first != last) {
3797 if (*first != UC('0')) {
3798 return true;
3799 }
3800 ++first;
3801 }
3802 return false;
3803}
3804
3805template <typename UC>
3806fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool
3807is_truncated(span<UC const> s) noexcept {
3808 return is_truncated(s.ptr, s.ptr + s.len());
3809}
3810
3811template <typename UC>
3812fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
3813parse_eight_digits(UC const *&p, limb &value, size_t &counter,
3814 size_t &count) noexcept {
3815 value = value * 100000000 + parse_eight_digits_unrolled(p);
3816 p += 8;
3817 counter += 8;
3818 count += 8;
3819}
3820
3821template <typename UC>
3822fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void
3823parse_one_digit(UC const *&p, limb &value, size_t &counter,
3824 size_t &count) noexcept {
3825 value = value * 10 + limb(*p - UC('0'));
3826 p++;
3827 counter++;
3828 count++;
3829}
3830
3831fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
3832add_native(bigint &big, limb power, limb value) noexcept {
3833 big.mul(power);
3834 big.add(value);
3835}
3836
3837fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
3838round_up_bigint(bigint &big, size_t &count) noexcept {
3839 // need to round-up the digits, but need to avoid rounding
3840 // ....9999 to ...10000, which could cause a false halfway point.
3841 add_native(big, 10, 1);
3842 count++;
3843}
3844
3845// parse the significant digits into a big integer
3846template <typename UC>
3847inline FASTFLOAT_CONSTEXPR20 void
3848parse_mantissa(bigint &result, parsed_number_string_t<UC> &num,
3849 size_t max_digits, size_t &digits) noexcept {
3850 // try to minimize the number of big integer and scalar multiplication.
3851 // therefore, try to parse 8 digits at a time, and multiply by the largest
3852 // scalar value (9 or 19 digits) for each step.
3853 size_t counter = 0;
3854 digits = 0;
3855 limb value = 0;
3856#ifdef FASTFLOAT_64BIT_LIMB
3857 size_t step = 19;
3858#else
3859 size_t step = 9;
3860#endif
3861
3862 // process all integer digits.
3863 UC const *p = num.integer.ptr;
3864 UC const *pend = p + num.integer.len();
3865 skip_zeros(p, pend);
3866 // process all digits, in increments of step per loop
3867 while (p != pend) {
3868 while ((std::distance(p, pend) >= 8) && (step - counter >= 8) &&
3869 (max_digits - digits >= 8)) {
3870 parse_eight_digits(p, value, counter, digits);
3871 }
3872 while (counter < step && p != pend && digits < max_digits) {
3873 parse_one_digit(p, value, counter, digits);
3874 }
3875 if (digits == max_digits) {
3876 // add the temporary value, then check if we've truncated any digits
3877 add_native(result, limb(powers_of_ten_uint64[counter]), value);
3878 bool truncated = is_truncated(p, pend);
3879 if (num.fraction.ptr != nullptr) {
3880 truncated |= is_truncated(num.fraction);
3881 }
3882 if (truncated) {
3883 round_up_bigint(result, digits);
3884 }
3885 return;
3886 } else {
3887 add_native(result, limb(powers_of_ten_uint64[counter]), value);
3888 counter = 0;
3889 value = 0;
3890 }
3891 }
3892
3893 // add our fraction digits, if they're available.
3894 if (num.fraction.ptr != nullptr) {
3895 p = num.fraction.ptr;
3896 pend = p + num.fraction.len();
3897 if (digits == 0) {
3898 skip_zeros(p, pend);
3899 }
3900 // process all digits, in increments of step per loop
3901 while (p != pend) {
3902 while ((std::distance(p, pend) >= 8) && (step - counter >= 8) &&
3903 (max_digits - digits >= 8)) {
3904 parse_eight_digits(p, value, counter, digits);
3905 }
3906 while (counter < step && p != pend && digits < max_digits) {
3907 parse_one_digit(p, value, counter, digits);
3908 }
3909 if (digits == max_digits) {
3910 // add the temporary value, then check if we've truncated any digits
3911 add_native(result, limb(powers_of_ten_uint64[counter]), value);
3912 bool truncated = is_truncated(p, pend);
3913 if (truncated) {
3914 round_up_bigint(result, digits);
3915 }
3916 return;
3917 } else {
3918 add_native(result, limb(powers_of_ten_uint64[counter]), value);
3919 counter = 0;
3920 value = 0;
3921 }
3922 }
3923 }
3924
3925 if (counter != 0) {
3926 add_native(result, limb(powers_of_ten_uint64[counter]), value);
3927 }
3928}
3929
3930template <typename T>
3931inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
3932positive_digit_comp(bigint &bigmant, int32_t exponent) noexcept {
3933 FASTFLOAT_ASSERT(bigmant.pow10(uint32_t(exponent)));
3934 adjusted_mantissa answer;
3935 bool truncated;
3936 answer.mantissa = bigmant.hi64(truncated);
3937 int bias = binary_format<T>::mantissa_explicit_bits() -
3938 binary_format<T>::minimum_exponent();
3939 answer.power2 = bigmant.bit_length() - 64 + bias;
3940
3941 round<T>(answer, [truncated](adjusted_mantissa &a, int32_t shift) {
3942 round_nearest_tie_even(
3943 a, shift,
3944 [truncated](bool is_odd, bool is_halfway, bool is_above) -> bool {
3945 return is_above || (is_halfway && truncated) ||
3946 (is_odd && is_halfway);
3947 });
3948 });
3949
3950 return answer;
3951}
3952
3953// the scaling here is quite simple: we have, for the real digits `m * 10^e`,
3954// and for the theoretical digits `n * 2^f`. Since `e` is always negative,
3955// to scale them identically, we do `n * 2^f * 5^-f`, so we now have `m * 2^e`.
3956// we then need to scale by `2^(f- e)`, and then the two significant digits
3957// are of the same magnitude.
3958template <typename T>
3959inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
3960 bigint &bigmant, adjusted_mantissa am, int32_t exponent) noexcept {
3961 bigint &real_digits = bigmant;
3962 int32_t real_exp = exponent;
3963
3964 // get the value of `b`, rounded down, and get a bigint representation of b+h
3965 adjusted_mantissa am_b = am;
3966 // gcc7 buf: use a lambda to remove the noexcept qualifier bug with
3967 // -Wnoexcept-type.
3968 round<T>(am_b,
3969 [](adjusted_mantissa &a, int32_t shift) { round_down(a, shift); });
3970 T b;
3971 to_float(false, am_b, b);
3972 adjusted_mantissa theor = to_extended_halfway(b);
3973 bigint theor_digits(theor.mantissa);
3974 int32_t theor_exp = theor.power2;
3975
3976 // scale real digits and theor digits to be same power.
3977 int32_t pow2_exp = theor_exp - real_exp;
3978 uint32_t pow5_exp = uint32_t(-real_exp);
3979 if (pow5_exp != 0) {
3980 FASTFLOAT_ASSERT(theor_digits.pow5(pow5_exp));
3981 }
3982 if (pow2_exp > 0) {
3983 FASTFLOAT_ASSERT(theor_digits.pow2(uint32_t(pow2_exp)));
3984 } else if (pow2_exp < 0) {
3985 FASTFLOAT_ASSERT(real_digits.pow2(uint32_t(-pow2_exp)));
3986 }
3987
3988 // compare digits, and use it to director rounding
3989 int ord = real_digits.compare(theor_digits);
3990 adjusted_mantissa answer = am;
3991 round<T>(answer, [ord](adjusted_mantissa &a, int32_t shift) {
3992 round_nearest_tie_even(
3993 a, shift, [ord](bool is_odd, bool _, bool __) -> bool {
3994 (void)_; // not needed, since we've done our comparison
3995 (void)__; // not needed, since we've done our comparison
3996 if (ord > 0) {
3997 return true;
3998 } else if (ord < 0) {
3999 return false;
4000 } else {
4001 return is_odd;
4002 }
4003 });
4004 });
4005
4006 return answer;
4007}
4008
4009// parse the significant digits as a big integer to unambiguously round the
4010// the significant digits. here, we are trying to determine how to round
4011// an extended float representation close to `b+h`, halfway between `b`
4012// (the float rounded-down) and `b+u`, the next positive float. this
4013// algorithm is always correct, and uses one of two approaches. when
4014// the exponent is positive relative to the significant digits (such as
4015// 1234), we create a big-integer representation, get the high 64-bits,
4016// determine if any lower bits are truncated, and use that to direct
4017// rounding. in case of a negative exponent relative to the significant
4018// digits (such as 1.2345), we create a theoretical representation of
4019// `b` as a big-integer type, scaled to the same binary exponent as
4020// the actual digits. we then compare the big integer representations
4021// of both, and use that to direct rounding.
4022template <typename T, typename UC>
4023inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
4024digit_comp(parsed_number_string_t<UC> &num, adjusted_mantissa am) noexcept {
4025 // remove the invalid exponent bias
4026 am.power2 -= invalid_am_bias;
4027
4028 int32_t sci_exp = scientific_exponent(num);
4029 size_t max_digits = binary_format<T>::max_digits();
4030 size_t digits = 0;
4031 bigint bigmant;
4032 parse_mantissa(bigmant, num, max_digits, digits);
4033 // can't underflow, since digits is at most max_digits.
4034 int32_t exponent = sci_exp + 1 - int32_t(digits);
4035 if (exponent >= 0) {
4036 return positive_digit_comp<T>(bigmant, exponent);
4037 } else {
4038 return negative_digit_comp<T>(bigmant, am, exponent);
4039 }
4040}
4041
4042} // namespace fast_float
4043
4044#endif
4045
4046#ifndef FASTFLOAT_PARSE_NUMBER_H
4047#define FASTFLOAT_PARSE_NUMBER_H
4048
4049
4050#include <cmath>
4051#include <cstring>
4052#include <limits>
4053#include <system_error>
4054
4055namespace fast_float {
4056
4057namespace detail {
4063template <typename T, typename UC>
4064from_chars_result_t<UC>
4065 FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first, UC const *last,
4066 T &value, chars_format fmt) noexcept {
4067 from_chars_result_t<UC> answer{};
4068 answer.ptr = first;
4069 answer.ec = std::errc(); // be optimistic
4070 // assume first < last, so dereference without checks;
4071 bool const minusSign = (*first == UC('-'));
4072 // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
4073 if ((*first == UC('-')) ||
4074 (uint64_t(fmt & chars_format::allow_leading_plus) &&
4075 (*first == UC('+')))) {
4076 ++first;
4077 }
4078 if (last - first >= 3) {
4079 if (fastfloat_strncasecmp(first, str_const_nan<UC>(), 3)) {
4080 answer.ptr = (first += 3);
4081 value = minusSign ? -std::numeric_limits<T>::quiet_NaN()
4082 : std::numeric_limits<T>::quiet_NaN();
4083 // Check for possible nan(n-char-seq-opt), C++17 20.19.3.7,
4084 // C11 7.20.1.3.3. At least MSVC produces nan(ind) and nan(snan).
4085 if (first != last && *first == UC('(')) {
4086 for (UC const *ptr = first + 1; ptr != last; ++ptr) {
4087 if (*ptr == UC(')')) {
4088 answer.ptr = ptr + 1; // valid nan(n-char-seq-opt)
4089 break;
4090 } else if (!((UC('a') <= *ptr && *ptr <= UC('z')) ||
4091 (UC('A') <= *ptr && *ptr <= UC('Z')) ||
4092 (UC('0') <= *ptr && *ptr <= UC('9')) || *ptr == UC('_')))
4093 break; // forbidden char, not nan(n-char-seq-opt)
4094 }
4095 }
4096 return answer;
4097 }
4098 if (fastfloat_strncasecmp(first, str_const_inf<UC>(), 3)) {
4099 if ((last - first >= 8) &&
4100 fastfloat_strncasecmp(first + 3, str_const_inf<UC>() + 3, 5)) {
4101 answer.ptr = first + 8;
4102 } else {
4103 answer.ptr = first + 3;
4104 }
4105 value = minusSign ? -std::numeric_limits<T>::infinity()
4106 : std::numeric_limits<T>::infinity();
4107 return answer;
4108 }
4109 }
4110 answer.ec = std::errc::invalid_argument;
4111 return answer;
4112}
4113
4119fastfloat_really_inline bool rounds_to_nearest() noexcept {
4120 // https://lemire.me/blog/2020/06/26/gcc-not-nearest/
4121#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0)
4122 return false;
4123#endif
4124 // See
4125 // A fast function to check your floating-point rounding mode
4126 // https://lemire.me/blog/2022/11/16/a-fast-function-to-check-your-floating-point-rounding-mode/
4127 //
4128 // This function is meant to be equivalent to :
4129 // prior: #include <cfenv>
4130 // return fegetround() == FE_TONEAREST;
4131 // However, it is expected to be much faster than the fegetround()
4132 // function call.
4133 //
4134 // The volatile keyword prevents the compiler from computing the function
4135 // at compile-time.
4136 // There might be other ways to prevent compile-time optimizations (e.g.,
4137 // asm). The value does not need to be std::numeric_limits<float>::min(), any
4138 // small value so that 1 + x should round to 1 would do (after accounting for
4139 // excess precision, as in 387 instructions).
4140 static float volatile fmin = std::numeric_limits<float>::min();
4141 float fmini = fmin; // we copy it so that it gets loaded at most once.
4142//
4143// Explanation:
4144// Only when fegetround() == FE_TONEAREST do we have that
4145// fmin + 1.0f == 1.0f - fmin.
4146//
4147// FE_UPWARD:
4148// fmin + 1.0f > 1
4149// 1.0f - fmin == 1
4150//
4151// FE_DOWNWARD or FE_TOWARDZERO:
4152// fmin + 1.0f == 1
4153// 1.0f - fmin < 1
4154//
4155// Note: This may fail to be accurate if fast-math has been
4156// enabled, as rounding conventions may not apply.
4157#ifdef FASTFLOAT_VISUAL_STUDIO
4158#pragma warning(push)
4159// todo: is there a VS warning?
4160// see
4161// https://stackoverflow.com/questions/46079446/is-there-a-warning-for-floating-point-equality-checking-in-visual-studio-2013
4162#elif defined(__clang__)
4163#pragma clang diagnostic push
4164#pragma clang diagnostic ignored "-Wfloat-equal"
4165#elif defined(__GNUC__)
4166#pragma GCC diagnostic push
4167#pragma GCC diagnostic ignored "-Wfloat-equal"
4168#endif
4169 return (fmini + 1.0f == 1.0f - fmini);
4170#ifdef FASTFLOAT_VISUAL_STUDIO
4171#pragma warning(pop)
4172#elif defined(__clang__)
4173#pragma clang diagnostic pop
4174#elif defined(__GNUC__)
4175#pragma GCC diagnostic pop
4176#endif
4177}
4178
4179} // namespace detail
4180
4181template <typename T> struct from_chars_caller {
4182 template <typename UC>
4183 FASTFLOAT_CONSTEXPR20 static from_chars_result_t<UC>
4184 call(UC const *first, UC const *last, T &value,
4185 parse_options_t<UC> options) noexcept {
4186 return from_chars_advanced(first, last, value, options);
4187 }
4188};
4189
4190#ifdef __STDCPP_FLOAT32_T__
4191template <> struct from_chars_caller<std::float32_t> {
4192 template <typename UC>
4193 FASTFLOAT_CONSTEXPR20 static from_chars_result_t<UC>
4194 call(UC const *first, UC const *last, std::float32_t &value,
4195 parse_options_t<UC> options) noexcept {
4196 // if std::float32_t is defined, and we are in C++23 mode; macro set for
4197 // float32; set value to float due to equivalence between float and
4198 // float32_t
4199 float val;
4200 auto ret = from_chars_advanced(first, last, val, options);
4201 value = val;
4202 return ret;
4203 }
4204};
4205#endif
4206
4207#ifdef __STDCPP_FLOAT64_T__
4208template <> struct from_chars_caller<std::float64_t> {
4209 template <typename UC>
4210 FASTFLOAT_CONSTEXPR20 static from_chars_result_t<UC>
4211 call(UC const *first, UC const *last, std::float64_t &value,
4212 parse_options_t<UC> options) noexcept {
4213 // if std::float64_t is defined, and we are in C++23 mode; macro set for
4214 // float64; set value as double due to equivalence between double and
4215 // float64_t
4216 double val;
4217 auto ret = from_chars_advanced(first, last, val, options);
4218 value = val;
4219 return ret;
4220 }
4221};
4222#endif
4223
4224template <typename T, typename UC, typename>
4225FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
4226from_chars(UC const *first, UC const *last, T &value,
4227 chars_format fmt /*= chars_format::general*/) noexcept {
4228 return from_chars_caller<T>::call(first, last, value,
4229 parse_options_t<UC>(fmt));
4230}
4231
4237template <typename T, typename UC>
4238FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
4239from_chars_advanced(parsed_number_string_t<UC> &pns, T &value) noexcept {
4240
4242 "only some floating-point types are supported");
4244 "only char, wchar_t, char16_t and char32_t are supported");
4245
4247
4248 answer.ec = std::errc(); // be optimistic
4249 answer.ptr = pns.lastmatch;
4250 // The implementation of the Clinger's fast path is convoluted because
4251 // we want round-to-nearest in all cases, irrespective of the rounding mode
4252 // selected on the thread.
4253 // We proceed optimistically, assuming that detail::rounds_to_nearest()
4254 // returns true.
4255 if (binary_format<T>::min_exponent_fast_path() <= pns.exponent &&
4256 pns.exponent <= binary_format<T>::max_exponent_fast_path() &&
4257 !pns.too_many_digits) {
4258 // Unfortunately, the conventional Clinger's fast path is only possible
4259 // when the system rounds to the nearest float.
4260 //
4261 // We expect the next branch to almost always be selected.
4262 // We could check it first (before the previous branch), but
4263 // there might be performance advantages at having the check
4264 // be last.
4265 if (!cpp20_and_in_constexpr() && detail::rounds_to_nearest()) {
4266 // We have that fegetround() == FE_TONEAREST.
4267 // Next is Clinger's fast path.
4268 if (pns.mantissa <= binary_format<T>::max_mantissa_fast_path()) {
4269 value = T(pns.mantissa);
4270 if (pns.exponent < 0) {
4271 value = value / binary_format<T>::exact_power_of_ten(-pns.exponent);
4272 } else {
4273 value = value * binary_format<T>::exact_power_of_ten(pns.exponent);
4274 }
4275 if (pns.negative) {
4276 value = -value;
4277 }
4278 return answer;
4279 }
4280 } else {
4281 // We do not have that fegetround() == FE_TONEAREST.
4282 // Next is a modified Clinger's fast path, inspired by Jakub Jelínek's
4283 // proposal
4284 if (pns.exponent >= 0 &&
4285 pns.mantissa <=
4286 binary_format<T>::max_mantissa_fast_path(pns.exponent)) {
4287#if defined(__clang__) || defined(FASTFLOAT_32BIT)
4288 // Clang may map 0 to -0.0 when fegetround() == FE_DOWNWARD
4289 if (pns.mantissa == 0) {
4290 value = pns.negative ? T(-0.) : T(0.);
4291 return answer;
4292 }
4293#endif
4294 value = T(pns.mantissa) *
4295 binary_format<T>::exact_power_of_ten(pns.exponent);
4296 if (pns.negative) {
4297 value = -value;
4298 }
4299 return answer;
4300 }
4301 }
4302 }
4303 adjusted_mantissa am =
4304 compute_float<binary_format<T>>(pns.exponent, pns.mantissa);
4305 if (pns.too_many_digits && am.power2 >= 0) {
4306 if (am != compute_float<binary_format<T>>(pns.exponent, pns.mantissa + 1)) {
4307 am = compute_error<binary_format<T>>(pns.exponent, pns.mantissa);
4308 }
4309 }
4310 // If we called compute_float<binary_format<T>>(pns.exponent, pns.mantissa)
4311 // and we have an invalid power (am.power2 < 0), then we need to go the long
4312 // way around again. This is very uncommon.
4313 if (am.power2 < 0) {
4314 am = digit_comp<T>(pns, am);
4315 }
4316 to_float(pns.negative, am, value);
4317 // Test for over/underflow.
4318 if ((pns.mantissa != 0 && am.mantissa == 0 && am.power2 == 0) ||
4319 am.power2 == binary_format<T>::infinite_power()) {
4320 answer.ec = std::errc::result_out_of_range;
4321 }
4322 return answer;
4323}
4324
4325template <typename T, typename UC>
4326FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
4327from_chars_float_advanced(UC const *first, UC const *last, T &value,
4328 parse_options_t<UC> options) noexcept {
4329
4331 "only some floating-point types are supported");
4333 "only char, wchar_t, char16_t and char32_t are supported");
4334
4335 chars_format const fmt = detail::adjust_for_feature_macros(options.format);
4336
4338 if (uint64_t(fmt & chars_format::skip_white_space)) {
4339 while ((first != last) && fast_float::is_space(*first)) {
4340 first++;
4341 }
4342 }
4343 if (first == last) {
4344 answer.ec = std::errc::invalid_argument;
4345 answer.ptr = first;
4346 return answer;
4347 }
4349 uint64_t(fmt & detail::basic_json_fmt)
4350 ? parse_number_string<true, UC>(first, last, options)
4351 : parse_number_string<false, UC>(first, last, options);
4352 if (!pns.valid) {
4353 if (uint64_t(fmt & chars_format::no_infnan)) {
4354 answer.ec = std::errc::invalid_argument;
4355 answer.ptr = first;
4356 return answer;
4357 } else {
4358 return detail::parse_infnan(first, last, value, fmt);
4359 }
4360 }
4361
4362 // call overload that takes parsed_number_string_t directly.
4363 return from_chars_advanced(pns, value);
4364}
4365
4366template <typename T, typename UC, typename>
4367FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
4368from_chars(UC const *first, UC const *last, T &value, int base) noexcept {
4369
4371 "only integer types are supported");
4373 "only char, wchar_t, char16_t and char32_t are supported");
4374
4375 parse_options_t<UC> options;
4376 options.base = base;
4377 return from_chars_advanced(first, last, value, options);
4378}
4379
4380template <typename T, typename UC>
4381FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
4382from_chars_int_advanced(UC const *first, UC const *last, T &value,
4383 parse_options_t<UC> options) noexcept {
4384
4386 "only integer types are supported");
4388 "only char, wchar_t, char16_t and char32_t are supported");
4389
4390 chars_format const fmt = detail::adjust_for_feature_macros(options.format);
4391 int const base = options.base;
4392
4394 if (uint64_t(fmt & chars_format::skip_white_space)) {
4395 while ((first != last) && fast_float::is_space(*first)) {
4396 first++;
4397 }
4398 }
4399 if (first == last || base < 2 || base > 36) {
4400 answer.ec = std::errc::invalid_argument;
4401 answer.ptr = first;
4402 return answer;
4403 }
4404
4405 return parse_int_string(first, last, value, options);
4406}
4407
4408template <size_t TypeIx> struct from_chars_advanced_caller {
4409 static_assert(TypeIx > 0, "unsupported type");
4410};
4411
4412template <> struct from_chars_advanced_caller<1> {
4413 template <typename T, typename UC>
4414 FASTFLOAT_CONSTEXPR20 static from_chars_result_t<UC>
4415 call(UC const *first, UC const *last, T &value,
4416 parse_options_t<UC> options) noexcept {
4417 return from_chars_float_advanced(first, last, value, options);
4418 }
4419};
4420
4421template <> struct from_chars_advanced_caller<2> {
4422 template <typename T, typename UC>
4423 FASTFLOAT_CONSTEXPR20 static from_chars_result_t<UC>
4424 call(UC const *first, UC const *last, T &value,
4425 parse_options_t<UC> options) noexcept {
4426 return from_chars_int_advanced(first, last, value, options);
4427 }
4428};
4429
4430template <typename T, typename UC>
4431FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
4432from_chars_advanced(UC const *first, UC const *last, T &value,
4433 parse_options_t<UC> options) noexcept {
4436 2 * size_t(is_supported_integer_type<T>::value)>::call(first, last, value,
4437 options);
4438}
4439
4440} // namespace fast_float
4441
4442#endif
4443
Definition fast_float.h:581
Definition fast_float.h:583
Definition fast_float.h:4408
Definition fast_float.h:4181
Definition fast_float.h:203
Definition fast_float.h:1222
Definition fast_float.h:406
Definition fast_float.h:384
Definition fast_float.h:395
Definition fast_float.h:210
int base
Definition fast_float.h:220
chars_format format
Definition fast_float.h:216
UC decimal_point
Definition fast_float.h:218
Definition fast_float.h:1697
Definition fast_float.h:2064
Definition fast_float.h:1141
Definition fast_float.h:428
Definition fast_float.h:2991
Definition fast_float.h:444