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