File: policy.h

package info (click to toggle)
webkit2gtk 2.48.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 429,620 kB
  • sloc: cpp: 3,696,936; javascript: 194,444; ansic: 169,997; python: 46,499; asm: 19,276; ruby: 18,528; perl: 16,602; xml: 4,650; yacc: 2,360; sh: 2,098; java: 1,993; lex: 1,327; pascal: 366; makefile: 298
file content (647 lines) | stat: -rw-r--r-- 27,251 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/*
 * Copyright (C) 2023 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * License header from dragonbox
 *    https://github.com/jk-jeon/dragonbox/blob/master/LICENSE-Boost
 *    https://github.com/jk-jeon/dragonbox/blob/master/LICENSE-Apache2-LLVM
 */

#pragma once

#include <wtf/dragonbox/detail/cache_holder.h>
#include <wtf/dragonbox/detail/decimal_fp.h>
#include <wtf/dragonbox/detail/log.h>
#include <wtf/dragonbox/detail/wuint.h>
#include <wtf/dragonbox/ieee754_format.h>

WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN

namespace WTF {

namespace dragonbox {

namespace detail {

////////////////////////////////////////////////////////////////////////////////////////
// Policies.
////////////////////////////////////////////////////////////////////////////////////////

// Forward declare the implementation class.
template<class Float, class FloatTraits = default_float_traits<Float>>
struct impl;

namespace policy_impl {

// Sign policies.
namespace sign {
struct base { };

struct ignore : base {
    using sign_policy = ignore;
    static constexpr bool return_has_sign = false;

    template<class SignedSignificandBits, class UnsignedDecimalFp>
    static constexpr UnsignedDecimalFp handle_sign(SignedSignificandBits, UnsignedDecimalFp r) noexcept
    {
        return r;
    }
};

struct return_sign : base {
    using sign_policy = return_sign;
    static constexpr bool return_has_sign = true;

    template<class SignedSignificandBits, class UnsignedDecimalFp>
    static constexpr unsigned_decimal_fp_to_signed_t<UnsignedDecimalFp>
    handle_sign(SignedSignificandBits s, UnsignedDecimalFp r) noexcept
    {
        return add_sign_to_unsigned_decimal_fp(s.is_negative(), r);
    }
};
} // namespace sign

// Trailing zero policies.
namespace trailing_zero {
struct base { };

struct ignore : base {
    using trailing_zero_policy = ignore;
    static constexpr bool report_trailing_zeros = false;

    template<class Impl, class ReturnType>
    static constexpr ReturnType
    on_trailing_zeros(typename Impl::carrier_uint significand, int32_t exponent) noexcept
    {
        return { significand, exponent };
    }

    template<class Impl, class ReturnType>
    static constexpr ReturnType
    no_trailing_zeros(typename Impl::carrier_uint significand, int32_t exponent) noexcept
    {
        return { significand, exponent };
    }
};

struct remove : base {
    using trailing_zero_policy = remove;
    static constexpr bool report_trailing_zeros = false;

    template<class Impl, class ReturnType>
    ALWAYS_INLINE static constexpr ReturnType
    on_trailing_zeros(typename Impl::carrier_uint significand, int32_t exponent) noexcept
    {
        return { (exponent += Impl::remove_trailing_zeros(significand), significand), exponent };
    }

    template<class Impl, class ReturnType>
    static constexpr ReturnType
    no_trailing_zeros(typename Impl::carrier_uint significand, int32_t exponent) noexcept
    {
        return { significand, exponent };
    }
};

struct report : base {
    using trailing_zero_policy = report;
    static constexpr bool report_trailing_zeros = true;

    template<class Impl, class ReturnType>
    static constexpr ReturnType
    on_trailing_zeros(typename Impl::carrier_uint significand, int32_t exponent) noexcept
    {
        return { significand, exponent, true };
    }

    template<class Impl, class ReturnType>
    static constexpr ReturnType
    no_trailing_zeros(typename Impl::carrier_uint significand, int32_t exponent) noexcept
    {
        return { significand, exponent, false };
    }
};
} // namespace trailing_zero

// Decimal-to-binary rounding mode policies.
namespace decimal_to_binary_rounding {
struct base { };

enum class tag_t { to_nearest,
    left_closed_directed,
    right_closed_directed };
namespace interval_type {
struct symmetric_boundary {
    static constexpr bool is_symmetric = true;
    bool is_closed;
    constexpr bool include_left_endpoint() const noexcept { return is_closed; }
    constexpr bool include_right_endpoint() const noexcept { return is_closed; }
};
struct asymmetric_boundary {
    static constexpr bool is_symmetric = false;
    bool is_left_closed;
    constexpr bool include_left_endpoint() const noexcept
    {
        return is_left_closed;
    }
    constexpr bool include_right_endpoint() const noexcept
    {
        return !is_left_closed;
    }
};
struct closed {
    static constexpr bool is_symmetric = true;
    static constexpr bool include_left_endpoint() noexcept { return true; }
    static constexpr bool include_right_endpoint() noexcept { return true; }
};
struct open {
    static constexpr bool is_symmetric = true;
    static constexpr bool include_left_endpoint() noexcept { return false; }
    static constexpr bool include_right_endpoint() noexcept { return false; }
};
struct left_closed_right_open {
    static constexpr bool is_symmetric = false;
    static constexpr bool include_left_endpoint() noexcept { return true; }
    static constexpr bool include_right_endpoint() noexcept { return false; }
};
struct right_closed_left_open {
    static constexpr bool is_symmetric = false;
    static constexpr bool include_left_endpoint() noexcept { return false; }
    static constexpr bool include_right_endpoint() noexcept { return true; }
};
} // namespace interval_type

struct nearest_to_even : base {
    using decimal_to_binary_rounding_policy = nearest_to_even;
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::symmetric_boundary;
    using shorter_interval_type = interval_type::closed;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(declval<nearest_to_even>(), Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(nearest_to_even { }, args...);
    }

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }..., false)) invoke_normal_interval_case(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return f(args..., s.has_even_significand_bits());
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_shorter_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
};
struct nearest_to_odd : base {
    using decimal_to_binary_rounding_policy = nearest_to_odd;
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::symmetric_boundary;
    using shorter_interval_type = interval_type::open;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(declval<nearest_to_odd>(), Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(nearest_to_odd { }, args...);
    }

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }..., false)) invoke_normal_interval_case(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return f(args..., !s.has_even_significand_bits());
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_shorter_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
};
struct nearest_toward_plus_infinity : base {
    using decimal_to_binary_rounding_policy = nearest_toward_plus_infinity;
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::asymmetric_boundary;
    using shorter_interval_type = interval_type::asymmetric_boundary;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(declval<nearest_toward_plus_infinity>(), Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(nearest_toward_plus_infinity { }, args...);
    }

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }..., false)) invoke_normal_interval_case(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return f(args..., !s.is_negative());
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }..., false)) invoke_shorter_interval_case(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return f(args..., !s.is_negative());
    }
};
struct nearest_toward_minus_infinity : base {
    using decimal_to_binary_rounding_policy = nearest_toward_minus_infinity;
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::asymmetric_boundary;
    using shorter_interval_type = interval_type::asymmetric_boundary;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(declval<nearest_toward_minus_infinity>(), Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(nearest_toward_minus_infinity { }, args...);
    }

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }..., false)) invoke_normal_interval_case(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return f(args..., s.is_negative());
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }..., false)) invoke_shorter_interval_case(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return f(args..., s.is_negative());
    }
};
struct nearest_toward_zero : base {
    using decimal_to_binary_rounding_policy = nearest_toward_zero;
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::right_closed_left_open;
    using shorter_interval_type = interval_type::right_closed_left_open;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(declval<nearest_toward_zero>(), Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(nearest_toward_zero { }, args...);
    }

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_normal_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_shorter_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
};
struct nearest_away_from_zero : base {
    using decimal_to_binary_rounding_policy = nearest_away_from_zero;
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::left_closed_right_open;
    using shorter_interval_type = interval_type::left_closed_right_open;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(declval<nearest_away_from_zero>(), Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(nearest_away_from_zero { }, args...);
    }

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_normal_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_shorter_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
};

namespace detail {
struct nearest_always_closed {
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::closed;
    using shorter_interval_type = interval_type::closed;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_normal_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_shorter_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
};
struct nearest_always_open {
    static constexpr auto tag = tag_t::to_nearest;
    using normal_interval_type = interval_type::open;
    using shorter_interval_type = interval_type::open;

    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_normal_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(Args { }...)) invoke_shorter_interval_case(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(args...);
    }
};
} // namespace detail

struct nearest_to_even_static_boundary : base {
    using decimal_to_binary_rounding_policy = nearest_to_even_static_boundary;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(detail::nearest_always_closed { }, Args { }...)) delegate(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return s.has_even_significand_bits()
            ? f(detail::nearest_always_closed { }, args...)
            : f(detail::nearest_always_open { }, args...);
    }
};
struct nearest_to_odd_static_boundary : base {
    using decimal_to_binary_rounding_policy = nearest_to_odd_static_boundary;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(detail::nearest_always_closed { }, Args { }...)) delegate(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return s.has_even_significand_bits()
            ? f(detail::nearest_always_open { }, args...)
            : f(detail::nearest_always_closed { }, args...);
    }
};
struct nearest_toward_plus_infinity_static_boundary : base {
    using decimal_to_binary_rounding_policy = nearest_toward_plus_infinity_static_boundary;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(nearest_toward_zero { }, Args { }...)) delegate(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return s.is_negative() ? f(nearest_toward_zero { }, args...) : f(nearest_away_from_zero { }, args...);
    }
};
struct nearest_toward_minus_infinity_static_boundary : base {
    using decimal_to_binary_rounding_policy = nearest_toward_minus_infinity_static_boundary;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(nearest_toward_zero { }, Args { }...)) delegate(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return s.is_negative() ? f(nearest_away_from_zero { }, args...) : f(nearest_toward_zero { }, args...);
    }
};

namespace detail {
struct left_closed_directed {
    static constexpr auto tag = tag_t::left_closed_directed;
};
struct right_closed_directed {
    static constexpr auto tag = tag_t::right_closed_directed;
};
} // namespace detail

struct toward_plus_infinity : base {
    using decimal_to_binary_rounding_policy = toward_plus_infinity;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(detail::left_closed_directed { }, Args { }...)) delegate(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return s.is_negative() ? f(detail::left_closed_directed { }, args...) : f(detail::right_closed_directed { }, args...);
    }
};
struct toward_minus_infinity : base {
    using decimal_to_binary_rounding_policy = toward_minus_infinity;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(detail::left_closed_directed { }, Args { }...)) delegate(SignedSignificandBits s, Func f, Args... args) noexcept
    {
        return s.is_negative() ? f(detail::right_closed_directed { }, args...) : f(detail::left_closed_directed { }, args...);
    }
};
struct toward_zero : base {
    using decimal_to_binary_rounding_policy = toward_zero;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(detail::left_closed_directed { }, Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(detail::left_closed_directed { }, args...);
    }
};
struct away_from_zero : base {
    using decimal_to_binary_rounding_policy = away_from_zero;
    template<class SignedSignificandBits, class Func, class... Args>
    ALWAYS_INLINE static constexpr decltype(Func { }(detail::right_closed_directed { }, Args { }...)) delegate(SignedSignificandBits, Func f, Args... args) noexcept
    {
        return f(detail::right_closed_directed { }, args...);
    }
};
} // namespace decimal_to_binary_rounding

// Binary-to-decimal rounding policies.
// (Always assumes nearest rounding modes.)
namespace binary_to_decimal_rounding {
struct base { };

enum class tag_t { do_not_care,
    to_even,
    to_odd,
    away_from_zero,
    toward_zero };

struct do_not_care : base {
    using binary_to_decimal_rounding_policy = do_not_care;
    static constexpr auto tag = tag_t::do_not_care;

    template<class CarrierUInt>
    static constexpr bool prefer_round_down(CarrierUInt) noexcept
    {
        return false;
    }
};

struct to_even : base {
    using binary_to_decimal_rounding_policy = to_even;
    static constexpr auto tag = tag_t::to_even;

    template<class CarrierUInt>
    static constexpr bool prefer_round_down(CarrierUInt significand) noexcept { return significand % 2; }
};

struct to_odd : base {
    using binary_to_decimal_rounding_policy = to_odd;
    static constexpr auto tag = tag_t::to_odd;

    template<class CarrierUInt>
    static constexpr bool prefer_round_down(CarrierUInt significand) noexcept { return !(significand % 2); }
};

struct away_from_zero : base {
    using binary_to_decimal_rounding_policy = away_from_zero;
    static constexpr auto tag = tag_t::away_from_zero;

    template<class CarrierUInt>
    static constexpr bool prefer_round_down(CarrierUInt) noexcept
    {
        return false;
    }
};

struct toward_zero : base {
    using binary_to_decimal_rounding_policy = toward_zero;
    static constexpr auto tag = tag_t::toward_zero;

    template<class CarrierUInt>
    static constexpr bool prefer_round_down(CarrierUInt) noexcept
    {
        return true;
    }
};
} // namespace binary_to_decimal_rounding

// Cache policies.
namespace cache {
struct base { };

struct full : base {
    using cache_policy = full;
    template<class FloatFormat>
    static constexpr typename cache_holder<FloatFormat>::cache_entry_type get_cache(int32_t k) noexcept
    {
        ASSERT(k >= cache_holder<FloatFormat>::min_k && k <= cache_holder<FloatFormat>::max_k);
        return cache_holder<FloatFormat>::cache[size_t(k - cache_holder<FloatFormat>::min_k)];
    }
};

struct compact : base {
    using cache_policy = compact;

    template<class FloatFormat, class Dummy = void>
    struct get_cache_impl {
        static constexpr typename cache_holder<FloatFormat>::cache_entry_type get_cache(int32_t k) noexcept
        {
            return full::get_cache<FloatFormat>(k);
        }
    };

    template<class Dummy>
    struct get_cache_impl<ieee754_binary64, Dummy> {
        static constexpr cache_holder<ieee754_binary64>::cache_entry_type get_cache(int32_t k) noexcept
        {
            // Compute the base index.
            auto const cache_index = static_cast<int32_t>(static_cast<uint32_t>(k - cache_holder<ieee754_binary64>::min_k) / compressed_cache_detail<>::compression_ratio);
            auto const kb = cache_index * compressed_cache_detail<>::compression_ratio + cache_holder<ieee754_binary64>::min_k;
            auto const offset = k - kb;

            // Get the base cache.
            auto const base_cache = compressed_cache_detail<>::compressed_cache.table[cache_index];

            if (!offset)
                return base_cache;

            uint64_t base_cache_high = static_cast<uint64_t>(base_cache >> 64);
            uint64_t base_cache_low = static_cast<uint64_t>(base_cache);

            // Compute the required amount of bit-shift.
            auto const alpha = log::floor_log2_pow10(kb + offset) - log::floor_log2_pow10(kb) - offset;
            ASSERT(alpha > 0 && alpha < 64);

            // Try to recover the real cache.
            auto const pow5 = compressed_cache_detail<>::pow5.table[offset];
            auto recovered_cache = wuint::umul128(base_cache_high, pow5);
            auto const middle_low = wuint::umul128(base_cache_low, pow5);

            uint64_t middle_low_high = static_cast<uint64_t>(middle_low >> 64);
            uint64_t middle_low_low = static_cast<uint64_t>(middle_low);
            uint64_t recovered_cache_high = static_cast<uint64_t>(recovered_cache >> 64);
            uint64_t recovered_cache_low = static_cast<uint64_t>(recovered_cache);

            recovered_cache += middle_low_high;

            auto const high_to_middle = recovered_cache_high << (64 - alpha);
            auto const middle_to_low = recovered_cache_low << (64 - alpha);

            recovered_cache = (static_cast<UInt128>((recovered_cache_low >> alpha) | high_to_middle) << 64)
                + static_cast<UInt128>((middle_low_low >> alpha) | middle_to_low);

            ASSERT(recovered_cache_low + 1);
            recovered_cache += 1;

            return recovered_cache;
        }
    };

    template<class FloatFormat>
    static constexpr typename cache_holder<FloatFormat>::cache_entry_type get_cache(int32_t k) noexcept
    {
        ASSERT(k >= cache_holder<FloatFormat>::min_k && k <= cache_holder<FloatFormat>::max_k);
        return get_cache_impl<FloatFormat>::get_cache(k);
    }
};
} // namespace cache

} // namespace policy_impl

} // namespace detail

namespace policy {
namespace sign {
inline constexpr auto ignore = detail::policy_impl::sign::ignore { };
inline constexpr auto return_sign = detail::policy_impl::sign::return_sign { };
}

namespace trailing_zero {
inline constexpr auto ignore = detail::policy_impl::trailing_zero::ignore { };
inline constexpr auto remove = detail::policy_impl::trailing_zero::remove { };
inline constexpr auto report = detail::policy_impl::trailing_zero::report { };
}

namespace decimal_to_binary_rounding {
inline constexpr auto nearest_to_even = detail::policy_impl::decimal_to_binary_rounding::nearest_to_even { };
inline constexpr auto nearest_to_odd = detail::policy_impl::decimal_to_binary_rounding::nearest_to_odd { };
inline constexpr auto nearest_toward_plus_infinity = detail::policy_impl::decimal_to_binary_rounding::nearest_toward_plus_infinity { };
inline constexpr auto nearest_toward_minus_infinity = detail::policy_impl::decimal_to_binary_rounding::nearest_toward_minus_infinity { };
inline constexpr auto nearest_toward_zero = detail::policy_impl::decimal_to_binary_rounding::nearest_toward_zero { };
inline constexpr auto nearest_away_from_zero = detail::policy_impl::decimal_to_binary_rounding::nearest_away_from_zero { };

inline constexpr auto nearest_to_even_static_boundary = detail::policy_impl::decimal_to_binary_rounding::nearest_to_even_static_boundary { };
inline constexpr auto nearest_to_odd_static_boundary = detail::policy_impl::decimal_to_binary_rounding::nearest_to_odd_static_boundary { };
inline constexpr auto nearest_toward_plus_infinity_static_boundary = detail::policy_impl::decimal_to_binary_rounding::nearest_toward_plus_infinity_static_boundary { };
inline constexpr auto nearest_toward_minus_infinity_static_boundary = detail::policy_impl::decimal_to_binary_rounding::nearest_toward_minus_infinity_static_boundary { };

inline constexpr auto toward_plus_infinity = detail::policy_impl::decimal_to_binary_rounding::toward_plus_infinity { };
inline constexpr auto toward_minus_infinity = detail::policy_impl::decimal_to_binary_rounding::toward_minus_infinity { };
inline constexpr auto toward_zero = detail::policy_impl::decimal_to_binary_rounding::toward_zero { };
inline constexpr auto away_from_zero = detail::policy_impl::decimal_to_binary_rounding::away_from_zero { };
}

namespace binary_to_decimal_rounding {
inline constexpr auto do_not_care = detail::policy_impl::binary_to_decimal_rounding::do_not_care { };
inline constexpr auto to_even = detail::policy_impl::binary_to_decimal_rounding::to_even { };
inline constexpr auto to_odd = detail::policy_impl::binary_to_decimal_rounding::to_odd { };
inline constexpr auto away_from_zero = detail::policy_impl::binary_to_decimal_rounding::away_from_zero { };
inline constexpr auto toward_zero = detail::policy_impl::binary_to_decimal_rounding::toward_zero { };
}

namespace cache {
inline constexpr auto full = detail::policy_impl::cache::full { };
inline constexpr auto compact = detail::policy_impl::cache::compact { };
}
}

} // namespace dragonbox

} // namespace WTF

WTF_ALLOW_UNSAFE_BUFFER_USAGE_END