DAW JSON Link
Loading...
Searching...
No Matches
daw_json_parse_real_power10.h
Go to the documentation of this file.
1// Copyright (c) Darrell Wright
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5//
6// Official repository: https://github.com/beached/daw_json_link
7//
8
9#pragma once
10
12
15
16#include <daw/daw_arith_traits.h>
17#include <daw/daw_cpp_feature_check.h>
18#include <daw/daw_is_constant_evaluated.h>
19#include <daw/daw_likely.h>
20
21#include <cmath>
22#include <cstddef>
23#include <cstdint>
24#include <limits>
25#if defined( DAW_JSON_HAS_FLOAT128 ) and defined( __STDCPP_FLOAT128_T__ )
26#include <stdfloat>
27#endif
28#include <type_traits>
29
30namespace daw::json {
31 inline namespace DAW_JSON_VER {
32 namespace json_details {
33 inline constexpr double dpow10_tbl[] = {
34 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
35 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
36 1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29,
37 1e30, 1e31, 1e32, 1e33, 1e34, 1e35, 1e36, 1e37, 1e38, 1e39,
38 1e40, 1e41, 1e42, 1e43, 1e44, 1e45, 1e46, 1e47, 1e48, 1e49,
39 1e50, 1e51, 1e52, 1e53, 1e54, 1e55, 1e56, 1e57, 1e58, 1e59,
40 1e60, 1e61, 1e62, 1e63, 1e64, 1e65, 1e66, 1e67, 1e68, 1e69,
41 1e70, 1e71, 1e72, 1e73, 1e74, 1e75, 1e76, 1e77, 1e78, 1e79,
42 1e80, 1e81, 1e82, 1e83, 1e84, 1e85, 1e86, 1e87, 1e88, 1e89,
43 1e90, 1e91, 1e92, 1e93, 1e94, 1e95, 1e96, 1e97, 1e98, 1e99,
44 1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109,
45 1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119,
46 1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129,
47 1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139,
48 1e140, 1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149,
49 1e150, 1e151, 1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159,
50 1e160, 1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169,
51 1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178, 1e179,
52 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188, 1e189,
53 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199,
54 1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209,
55 1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219,
56 1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229,
57 1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239,
58 1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249,
59 1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259,
60 1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269,
61 1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279,
62 1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286, 1e287, 1e288, 1e289,
63 1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296, 1e297, 1e298, 1e299,
64 1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308 };
65
66 // 10^0 .. 10^27 are exactly representable in 80-bit long double
67 // (5^27 < 2^64), and 10^0 .. 10^48 in binary128 (5^48 < 2^113).
68 // Entries above 22 must not be sourced from the double table.
69 inline constexpr long double ldpow10_tbl[] = {
70 1e0L, 1e1L, 1e2L, 1e3L, 1e4L, 1e5L, 1e6L,
71 1e7L, 1e8L, 1e9L, 1e10L, 1e11L, 1e12L, 1e13L,
72 1e14L, 1e15L, 1e16L, 1e17L, 1e18L, 1e19L, 1e20L,
73 1e21L, 1e22L, 1e23L, 1e24L, 1e25L, 1e26L, 1e27L,
74 1e28L, 1e29L, 1e30L, 1e31L, 1e32L, 1e33L, 1e34L,
75 1e35L, 1e36L, 1e37L, 1e38L, 1e39L, 1e40L, 1e41L,
76 1e42L, 1e43L, 1e44L, 1e45L, 1e46L, 1e47L, 1e48L,
77 };
78 inline constexpr int max_ld_table_exp = 48;
79
80 inline constexpr int max_dbl_exp =
81 std::numeric_limits<double>::max_exponent10;
82
83 template<typename T>
84 [[nodiscard]] DAW_ATTRIB_INLINE constexpr T const &
85 Min( T const &l, T const &r ) noexcept {
86 if( l <= r ) {
87 return l;
88 }
89 return r;
90 }
91
92 template<typename Result>
93 inline constexpr int max_exp =
94 std::is_same_v<Result, float>
95 ? Min( max_dbl_exp, std::numeric_limits<float>::max_exponent10 )
96 : max_dbl_exp;
97
98 template<typename Result, typename Unsigned>
99 [[nodiscard]] DAW_ATTRIB_FLATINLINE constexpr Result
100 power10_constexpr( Result result, Unsigned p ) {
101 // For extended long double use the exact LD table where available;
102 // the double table loses precision for p above 22.
103 if constexpr( is_double_sized_long_double_v<Result> == false and
104 std::is_same_v<Result, long double> ) {
105 DAW_CPP23_STATIC_LOCAL constexpr int max_exact_exp =
106 std::numeric_limits<long double>::digits == 113
107 ? max_ld_table_exp
108 : 27;
109 if( p >= -max_exact_exp and p <= max_exact_exp ) {
110 if( p < 0 ) {
111 return result /
112 ldpow10_tbl[static_cast<std::size_t>( -p )];
113 }
114 return result * ldpow10_tbl[static_cast<std::size_t>( p )];
115 }
116 }
117
118 DAW_CPP23_STATIC_LOCAL constexpr auto max_v =
119 static_cast<Result>( dpow10_tbl[max_exp<Result>] );
120
121 if( DAW_UNLIKELY( p > max_exp<Result> ) ) {
122 if constexpr( std::is_floating_point_v<Result> ) {
123 if( DAW_UNLIKELY( p >
124 daw::numeric_limits<Result>::max_exponent ) ) {
125 return std::numeric_limits<Result>::infinity( );
126 }
127 }
128 Result exp2 = max_v;
129 p -= max_exp<Result>;
130
131 for( ; p > max_exp<Result>; p -= max_exp<Result> ) {
132 exp2 *= max_v;
133 }
134 return static_cast<Result>( result ) *
135 ( exp2 * static_cast<Result>(
136 dpow10_tbl[static_cast<std::size_t>( p )] ) );
137 }
138 if( DAW_UNLIKELY( p < -max_exp<Result> ) ) {
139 if constexpr( std::is_floating_point_v<Result> ) {
140 if( DAW_UNLIKELY( p <
141 daw::numeric_limits<Result>::min_exponent ) ) {
142 return Result{ 0 };
143 }
144 }
145 Result exp2 = max_v;
146 p += max_exp<Result>;
147
148 for( ; p < -max_exp<Result>; p += max_exp<Result> ) {
149 result /= max_v;
150 }
151 return ( static_cast<Result>( result ) /
152 static_cast<Result>(
153 dpow10_tbl[static_cast<std::size_t>( -p )] ) ) /
154 exp2;
155 }
156 if( p < 0 ) {
157 return static_cast<Result>( result ) /
158 static_cast<Result>(
159 dpow10_tbl[static_cast<std::size_t>( -p )] );
160 }
161 return static_cast<Result>( result ) *
162 static_cast<Result>( dpow10_tbl[static_cast<std::size_t>( p )] );
163 }
164
165 namespace power10_details {
167 inline constexpr std::uint32_t max_exact_double_power10 = 22;
168
176 template<typename Result>
177 [[nodiscard]] constexpr Result power10_value( std::uint32_t n ) {
178 auto power =
179 static_cast<Result>( dpow10_tbl[n % max_exact_double_power10] );
180 auto q = n / max_exact_double_power10;
181 if( q != 0 ) {
182 auto base =
183 static_cast<Result>( dpow10_tbl[max_exact_double_power10] );
184 while( true ) {
185 if( ( q & 1U ) != 0 ) {
186 power = power * base;
187 }
188 q >>= 1U;
189 if( q == 0 ) {
190 break;
191 }
192 base = base * base;
193 }
194 }
195 return power;
196 }
197 } // namespace power10_details
198
207 template<typename Result>
208 [[nodiscard]] constexpr Result power10_by_squaring( Result result,
209 std::int64_t p ) {
210 using limits = std::numeric_limits<Result>;
211 // Apply at most 10^chunk at a time so the power itself cannot overflow
212 // when result * 10^p is still representable
213 DAW_CPP23_STATIC_LOCAL constexpr std::uint32_t chunk =
214 limits::max_exponent10 > 0
215 ? static_cast<std::uint32_t>( limits::max_exponent10 )
216 : power10_details::max_exact_double_power10;
217 // After this many chunks any finite result is already 0 or infinity
218 DAW_CPP23_STATIC_LOCAL constexpr std::uint64_t max_chunks =
219 static_cast<std::uint64_t>(
220 ( limits::max_exponent10 - limits::min_exponent10 ) > 0
221 ? ( limits::max_exponent10 - limits::min_exponent10 )
222 : 0 ) /
223 chunk +
224 2U;
225
226 bool const negative = p < 0;
227 auto n = negative ? std::uint64_t{ 0 } - static_cast<std::uint64_t>( p )
228 : static_cast<std::uint64_t>( p );
229 // Overflowing to infinity is not allowed in a constant expression, so
230 // check before multiplying and return the overflow value directly
231 bool overflowed = false;
232 auto const scale = [&]( Result value, Result const &power ) -> Result {
233 if( negative ) {
234 return value / power;
235 }
236 if( DAW_UNLIKELY( value > limits::max( ) / power ) ) {
237 overflowed = true;
238 if constexpr( limits::has_infinity ) {
239 return limits::infinity( );
240 } else {
241 return limits::max( );
242 }
243 }
244 return value * power;
245 };
246 if( DAW_UNLIKELY( n > chunk ) ) {
247 auto const chunk_power =
248 power10_details::power10_value<Result>( chunk );
249 std::uint64_t chunks = 0;
250 while( n > chunk and chunks < max_chunks ) {
251 result = scale( result, chunk_power );
252 if( overflowed ) {
253 return result;
254 }
255 n -= chunk;
256 ++chunks;
257 }
258 if( n > chunk ) {
259 n = chunk;
260 }
261 }
262 return scale( result,
263 power10_details::power10_value<Result>(
264 static_cast<std::uint32_t>( n ) ) );
265 }
266
267#if defined( DAW_JSON_HAS_FLOAT128 )
268 namespace power10_details {
269 inline constexpr int float128_max_exponent = 16384;
270 inline constexpr int float128_min_exponent = -16381;
271#if defined( __STDCPP_FLOAT128_T__ )
272 using float128_t = std::float128_t;
273#else
274 using float128_t = __float128;
275#endif
276 inline constexpr int float128_digits = 113;
277
281 [[nodiscard]] constexpr float128_t make_float128( bool negative,
282 std::uint64_t sig_hi,
283 std::uint64_t sig_lo,
284 int exp2 ) {
285 auto value = static_cast<float128_t>( sig_hi ) *
286 static_cast<float128_t>( 18446744073709551616.0 ) +
287 static_cast<float128_t>( sig_lo );
288 auto base = static_cast<float128_t>( exp2 < 0 ? 0.5 : 2.0 );
289 auto n = static_cast<unsigned>( exp2 < 0 ? -exp2 : exp2 );
290 while( n != 0 ) {
291 if( ( n & 1U ) != 0 ) {
292 value = value * base;
293 }
294 n >>= 1U;
295 if( n != 0 ) {
296 base = base * base;
297 }
298 }
299 return negative ? -value : value;
300 }
301
303 struct float128_pair {
304 float128_t hi;
305 float128_t lo;
306 };
307
310 [[nodiscard]] constexpr float128_t
311 product_error( float128_t a, float128_t b,
312 [[maybe_unused]] float128_t p ) {
313#if defined( __FP_FAST_FMAF128 )
314 // Only with a hardware fma. Without one, e.g. x86-64, fmaf128 is
315 // done in software and is slower than the product below
316 if( not DAW_IS_CONSTANT_EVALUATED_COMPAT( ) ) {
317#if defined( __STDCPP_FLOAT128_T__ )
318 return std::fma( a, b, -p );
319#elif DAW_HAS_BUILTIN( __builtin_fmaf128 )
320 return __builtin_fmaf128( a, b, -p );
321#endif
322 }
323#endif
324 // Veltkamp split, 2^57 + 1 for a 113 bit significand. Large
325 // operands are scaled down first so the split cannot overflow;
326 // scaling by a power of two is exact
327 DAW_CPP23_STATIC_LOCAL constexpr auto splitter =
328 static_cast<float128_t>( std::uint64_t{ 144115188075855873ULL } );
329 DAW_CPP23_STATIC_LOCAL constexpr float128_t big =
330 make_float128( false, 0, 1, 16000 );
331 DAW_CPP23_STATIC_LOCAL constexpr float128_t down =
332 make_float128( false, 0, 1, -80 );
333 DAW_CPP23_STATIC_LOCAL constexpr float128_t up =
334 make_float128( false, 0, 1, 80 );
335 auto scale = static_cast<float128_t>( 1 );
336 if( a > big or a < -big ) {
337 a = a * down;
338 scale = scale * up;
339 }
340 if( b > big or b < -big ) {
341 b = b * down;
342 scale = scale * up;
343 }
344 auto const split = []( float128_t x ) {
345 auto const c = splitter * x;
346 auto const hi = c - ( c - x );
347 return float128_pair{ hi, x - hi };
348 };
349 auto const sa = split( a );
350 auto const sb = split( b );
351 auto const scaled_p = a * b;
352 return ( ( ( ( sa.hi * sb.hi - scaled_p ) + sa.hi * sb.lo ) +
353 sa.lo * sb.hi ) +
354 sa.lo * sb.lo ) *
355 scale;
356 }
357
358 [[nodiscard]] constexpr float128_pair multiply( float128_pair a,
359 float128_pair b ) {
360 auto const p = a.hi * b.hi;
361 auto const e =
362 product_error( a.hi, b.hi, p ) + ( a.hi * b.lo + a.lo * b.hi );
363 auto const s = p + e;
364 return { s, e - ( s - p ) };
365 }
366
367 [[nodiscard]] constexpr float128_pair divide( float128_pair a,
368 float128_pair b ) {
369 auto const q1 = a.hi / b.hi;
370 auto const p = q1 * b.hi;
371 auto const r =
372 ( ( a.hi - p ) - product_error( q1, b.hi, p ) + a.lo ) - q1 * b.lo;
373 auto const q2 = r / b.hi;
374 auto const s = q1 + q2;
375 return { s, q2 - ( s - q1 ) };
376 }
377
380 inline constexpr float128_t power10_hi[] = {
381 static_cast<float128_t>( 1e16 ),
382 static_cast<float128_t>( 1e16 ) * static_cast<float128_t>( 1e16 ),
383 make_float128( false, 0x184f03e93ff9f, 0x4daa797ed6e38ed6, 100 ),
384 make_float128( false, 0x127748f9301d3, 0x19bf8cde66d86d62, 313 ),
385 make_float128( false, 0x154fdd7f73bf3, 0xbd1bbb77203731fe, 738 ),
386 make_float128( false, 0x1c633415d4c1d, 0x238d98cab8a978a1, 1588 ),
387 make_float128( false, 0x192eceb0d02ea, 0x182eca1a7a51e317, 3289 ),
388 make_float128( false, 0x13d1676bb8a7a, 0xbbc94e9a519c6536, 6691 ),
389 make_float128( false, 0x188c0a4051441, 0x2f3592982a7f0095, 13494 ) };
390 inline constexpr float128_t power10_lo[] = {
391 static_cast<float128_t>( 0 ),
392 static_cast<float128_t>( 0 ),
393 make_float128( false, 0x12fda87c04000, 0x0000000000000000, -14 ),
394 make_float128( false, 0x1370234f3fd7b, 0x08dd390bc3c54e3f, 194 ),
395 make_float128( true, 0x15487ae1b340c, 0x21d06755187f3801, 623 ),
396 make_float128( true, 0x1383b1cd3e33f, 0x17659a2dee9638ae, 1474 ),
397 make_float128( true, 0x1798d6ca33bec, 0x56db2781485a496c, 3175 ),
398 make_float128( true, 0x18d6cae734220, 0xa0e7e584475598ea, 6577 ),
399 make_float128( true, 0x1ab6cd44f026d, 0xdd8eecc1151841b6, 13380 ) };
400
402 [[nodiscard]] constexpr float128_pair power10_pair( std::uint32_t n ) {
403 auto power =
404 float128_pair{ static_cast<float128_t>( dpow10_tbl[n & 15U] ),
405 static_cast<float128_t>( 0 ) };
406 auto bits = n >> 4U;
407 for( std::size_t k = 0; bits != 0; ++k, bits >>= 1U ) {
408 if( ( bits & 1U ) != 0 ) {
409 power = multiply( power, { power10_hi[k], power10_lo[k] } );
410 }
411 }
412 return power;
413 }
414
418 [[nodiscard]] constexpr bool scale_float128( float128_t &value,
419 std::int64_t p ) {
420 // 10^4932 is the largest power below the binary128 maximum
421 DAW_CPP23_STATIC_LOCAL constexpr std::uint32_t chunk = 4932;
422 DAW_CPP23_STATIC_LOCAL constexpr float128_t max_value = make_float128(
423 false, 0x1ffffffffffff, 0xffffffffffffffff, 16383 - 112 );
424 bool const negative = p < 0;
425 auto n = negative
426 ? std::uint64_t{ 0 } - static_cast<std::uint64_t>( p )
427 : static_cast<std::uint64_t>( p );
428 // 10^n is exact in binary128 up to 10^48, but the double table is
429 // only exact up to 10^22, so 10^22 * 10^22 bounds this. A single
430 // multiply or divide by an exact power is correctly rounded
431 if( n <= 44 ) {
432 auto const power =
433 n <= 22 ? static_cast<float128_t>( dpow10_tbl[n] )
434 : static_cast<float128_t>( dpow10_tbl[22] ) *
435 static_cast<float128_t>( dpow10_tbl[n - 22] );
436 if( negative ) {
437 value = value / power;
438 return true;
439 }
440 if( value > max_value / power ) {
441 return false;
442 }
443 value = value * power;
444 return true;
445 }
446 auto v = float128_pair{ value, static_cast<float128_t>( 0 ) };
447 auto const apply = [&]( float128_pair const &power ) {
448 if( negative ) {
449 v = divide( v, power );
450 return true;
451 }
452 if( v.hi > max_value / power.hi ) {
453 return false;
454 }
455 v = multiply( v, power );
456 return true;
457 };
458 // Three chunks take any finite value past the binary128 range
459 for( int chunks = 0; n > chunk and chunks < 3; ++chunks ) {
460 if( not apply( power10_pair( chunk ) ) ) {
461 return false;
462 }
463 n -= chunk;
464 }
465 if( n > chunk ) {
466 n = chunk;
467 }
468 if( not apply( power10_pair( static_cast<std::uint32_t>( n ) ) ) ) {
469 return false;
470 }
471 value = v.hi + v.lo;
472 return true;
473 }
474
475#if defined( __STDCPP_FLOAT128_T__ ) and defined( __SIZEOF_FLOAT128__ )
479 using other_float128_t = __float128;
480#else
481 using other_float128_t = float128_t;
482#endif
483
484#if defined( __STDCPP_FLOAT128_T__ )
485 template<typename F>
486 inline constexpr bool is_std_float128_v =
487 std::is_same_v<F, std::float128_t>;
488#else
489 template<typename F>
490 inline constexpr bool is_std_float128_v = false;
491#endif
492
498 template<typename Result, typename F>
499 inline constexpr bool converts_from_v =
500 std::is_floating_point_v<F> and std::is_constructible_v<Result, F> and
501 ( std::is_floating_point_v<Result> or is_std_float128_v<F> );
502
503 template<typename Result, typename F>
504 inline constexpr bool converts_to_v =
505 std::is_floating_point_v<F> and std::is_constructible_v<F, Result> and
506 ( std::is_floating_point_v<Result> or is_std_float128_v<F> );
507
508 template<typename Result>
509 inline constexpr bool converts_from_float128_v =
510 converts_from_v<Result, float128_t> or
511 converts_from_v<Result, other_float128_t>;
512
513 template<typename Result>
514 inline constexpr bool converts_to_float128_v =
515 converts_to_v<Result, float128_t> or
516 converts_to_v<Result, other_float128_t>;
517
523 template<typename Result>
524 inline constexpr bool uses_float128_v =
525 ( std::numeric_limits<Result>::radix == 2 ) and
526 ( std::numeric_limits<Result>::digits >
527 std::numeric_limits<double>::digits ) and
528 ( std::numeric_limits<Result>::digits <= float128_digits ) and
529 ( std::numeric_limits<Result>::max_exponent <=
530 float128_max_exponent ) and
531 ( std::numeric_limits<Result>::min_exponent >=
532 float128_min_exponent - 1 ) and
533 converts_from_float128_v<Result> and converts_to_float128_v<Result>;
534
535 template<typename Result>
536 [[nodiscard]] constexpr float128_t to_float128( Result const &value ) {
537 if constexpr( converts_to_v<Result, float128_t> ) {
538 return static_cast<float128_t>( value );
539 } else {
540 return static_cast<float128_t>(
541 static_cast<other_float128_t>( value ) );
542 }
543 }
544
545 template<typename Result>
546 [[nodiscard]] constexpr Result from_float128( float128_t value ) {
547 if constexpr( converts_from_v<Result, float128_t> ) {
548 return static_cast<Result>( value );
549 } else {
550 return static_cast<Result>(
551 static_cast<other_float128_t>( value ) );
552 }
553 }
554 } // namespace power10_details
555#endif
556
561 template<typename Result>
562 [[nodiscard]] constexpr Result power10_wide( Result result,
563 std::int64_t p ) {
564#if defined( DAW_JSON_HAS_FLOAT128 )
565 if constexpr( power10_details::uses_float128_v<Result> ) {
566 auto value = power10_details::to_float128( result );
567 if( DAW_LIKELY( power10_details::scale_float128( value, p ) ) ) {
568 return power10_details::from_float128<Result>( value );
569 }
570 using limits = std::numeric_limits<Result>;
571 if constexpr( limits::has_infinity ) {
572 return limits::infinity( );
573 } else {
574 return limits::max( );
575 }
576 } else {
577 return power10_by_squaring( result, p );
578 }
579#else
580 return power10_by_squaring( result, p );
581#endif
582 }
583
584 template<typename Result, typename Unsigned>
585 [[nodiscard]] DAW_ATTRIB_FLATINLINE constexpr Result
586 power10_runtime( Result result, Unsigned p ) {
587 if constexpr( std::is_same_v<Result, double> or
588 std::is_same_v<Result, float> ) {
589 return power10_constexpr( result, static_cast<std::int32_t>( p ) );
590 } else if constexpr( is_double_sized_long_double_v<Result> ) {
591 // long double here has no more precision than double, so the
592 // double-precision table used by power10_constexpr loses nothing.
593 return static_cast<Result>( power10_constexpr(
594 static_cast<double>( result ), static_cast<std::int32_t>( p ) ) );
595 } else {
596 // Extended long double: power10_constexpr uses the exact LD table
597 // for all exponents the precise parser routes here.
598 return power10_constexpr( result, static_cast<std::int32_t>( p ) );
599 }
600 }
601
602 template<typename Result, typename ExecTag, typename Unsigned>
603 [[nodiscard]] DAW_ATTRIB_FLATINLINE constexpr Result
604 power10( ExecTag, Result result, Unsigned p ) {
605 if( use_constexpr_exec_mode<ExecTag>( ) ) {
606 return power10_constexpr<Result>( result, p );
607 }
608 return power10_runtime<Result>( result, p );
609 }
610 } // namespace json_details
611 } // namespace DAW_JSON_VER
612} // namespace daw::json
string_writer grows its string with resize_and_overwrite, leaving the new bytes uninitialized,...
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20