1// Copyright (c) Microsoft Corporation.
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3
4#ifndef DOUBLE_HEX_PRECISION_TO_CHARS_TEST_CASES_HPP
5#define DOUBLE_HEX_PRECISION_TO_CHARS_TEST_CASES_HPP
6
7#include <charconv>
8
9#include "test.hpp"
10using namespace std;
11
12inline constexpr DoublePrecisionToCharsTestCase double_hex_precision_to_chars_test_cases[] = {
13 // Test special cases (zero, inf, nan) and an ordinary case. Also test negative signs.
14 {.value: 0.0, .fmt: chars_format::hex, .precision: 4, .correct: "0.0000p+0"},
15 {.value: -0.0, .fmt: chars_format::hex, .precision: 4, .correct: "-0.0000p+0"},
16 {.value: double_inf, .fmt: chars_format::hex, .precision: 4, .correct: "inf"},
17 {.value: -double_inf, .fmt: chars_format::hex, .precision: 4, .correct: "-inf"},
18 {.value: double_nan, .fmt: chars_format::hex, .precision: 4, .correct: "nan"},
19 {.value: -double_nan, .fmt: chars_format::hex, .precision: 4, .correct: "-nan(ind)"},
20 {.value: double_nan_payload, .fmt: chars_format::hex, .precision: 4, .correct: "nan"},
21 {.value: -double_nan_payload, .fmt: chars_format::hex, .precision: 4, .correct: "-nan"},
22 {.value: 0x1.729p+0, .fmt: chars_format::hex, .precision: 4, .correct: "1.7290p+0"},
23 {.value: -0x1.729p+0, .fmt: chars_format::hex, .precision: 4, .correct: "-1.7290p+0"},
24
25 // Test hexfloat corner cases.
26 {.value: 0x1.728p+0, .fmt: chars_format::hex, .precision: 13, .correct: "1.7280000000000p+0"},
27 {.value: 0x0.0000000000001p-1022, .fmt: chars_format::hex, .precision: 13, .correct: "0.0000000000001p-1022"}, // min subnormal
28 {.value: 0x0.fffffffffffffp-1022, .fmt: chars_format::hex, .precision: 13, .correct: "0.fffffffffffffp-1022"}, // max subnormal
29 {.value: 0x1p-1022, .fmt: chars_format::hex, .precision: 13, .correct: "1.0000000000000p-1022"}, // min normal
30 {.value: 0x1.fffffffffffffp+1023, .fmt: chars_format::hex, .precision: 13, .correct: "1.fffffffffffffp+1023"}, // max normal
31
32 // Test hexfloat exponents.
33 {.value: 0x1p-1009, .fmt: chars_format::hex, .precision: 0, .correct: "1p-1009"},
34 {.value: 0x1p-999, .fmt: chars_format::hex, .precision: 0, .correct: "1p-999"},
35 {.value: 0x1p-99, .fmt: chars_format::hex, .precision: 0, .correct: "1p-99"},
36 {.value: 0x1p-9, .fmt: chars_format::hex, .precision: 0, .correct: "1p-9"},
37 {.value: 0x1p+0, .fmt: chars_format::hex, .precision: 0, .correct: "1p+0"},
38 {.value: 0x1p+9, .fmt: chars_format::hex, .precision: 0, .correct: "1p+9"},
39 {.value: 0x1p+99, .fmt: chars_format::hex, .precision: 0, .correct: "1p+99"},
40 {.value: 0x1p+999, .fmt: chars_format::hex, .precision: 0, .correct: "1p+999"},
41 {.value: 0x1p+1009, .fmt: chars_format::hex, .precision: 0, .correct: "1p+1009"},
42
43 // Test hexfloat hexits.
44 {.value: 0x1.01234567p+0, .fmt: chars_format::hex, .precision: 8, .correct: "1.01234567p+0"},
45 {.value: 0x1.89abcdefp+0, .fmt: chars_format::hex, .precision: 8, .correct: "1.89abcdefp+0"},
46
47 // Test varying precision. Negative precision requests full precision, not shortest round-trip.
48 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: -2, .correct: "1.1234561234561p+0"},
49 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: -1, .correct: "1.1234561234561p+0"},
50 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 0, .correct: "1p+0"},
51 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 1, .correct: "1.1p+0"},
52 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.12p+0"},
53 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 3, .correct: "1.123p+0"},
54 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 4, .correct: "1.1234p+0"},
55 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 5, .correct: "1.12345p+0"},
56 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 6, .correct: "1.123456p+0"},
57 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 7, .correct: "1.1234561p+0"},
58 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 8, .correct: "1.12345612p+0"},
59 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 9, .correct: "1.123456123p+0"},
60 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 10, .correct: "1.1234561234p+0"},
61 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 11, .correct: "1.12345612345p+0"},
62 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 12, .correct: "1.123456123456p+0"},
63 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 13, .correct: "1.1234561234561p+0"},
64 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 14, .correct: "1.12345612345610p+0"},
65 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 15, .correct: "1.123456123456100p+0"},
66 {.value: 0x1.1234561234561p+0, .fmt: chars_format::hex, .precision: 16, .correct: "1.1234561234561000p+0"},
67
68 // Test rounding at every position.
69 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 0, .correct: "2p+0"},
70 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 1, .correct: "1.dp+0"},
71 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.cdp+0"},
72 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 3, .correct: "1.ccdp+0"},
73 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 4, .correct: "1.cccdp+0"},
74 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 5, .correct: "1.ccccdp+0"},
75 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 6, .correct: "1.cccccdp+0"},
76 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 7, .correct: "1.ccccccdp+0"},
77 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 8, .correct: "1.cccccccdp+0"},
78 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 9, .correct: "1.ccccccccdp+0"},
79 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 10, .correct: "1.cccccccccdp+0"},
80 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 11, .correct: "1.ccccccccccdp+0"},
81 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 12, .correct: "1.cccccccccccdp+0"},
82 {.value: 0x1.cccccccccccccp+0, .fmt: chars_format::hex, .precision: 13, .correct: "1.cccccccccccccp+0"},
83
84 // Test all combinations of least significant bit, round bit, and trailing bits.
85 {.value: 0x1.04000p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.04p+0"}, // Lsb 0, Round 0, Trailing 0
86 {.value: 0x1.04001p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.04p+0"}, // Lsb 0, Round 0 and Trailing 1 in different hexits
87 {.value: 0x1.04200p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.04p+0"}, // Lsb 0, Round 0 and Trailing 1 in same hexit
88 {.value: 0x1.04800p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.04p+0"}, // Lsb 0, Round 1, Trailing 0
89 {.value: 0x1.04801p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.05p+0"}, // Lsb 0, Round 1 and Trailing 1 in different hexits
90 {.value: 0x1.04900p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.05p+0"}, // Lsb 0, Round 1 and Trailing 1 in same hexit
91 {.value: 0x1.05000p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.05p+0"}, // Lsb 1, Round 0, Trailing 0
92 {.value: 0x1.05001p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.05p+0"}, // Lsb 1, Round 0 and Trailing 1 in different hexits
93 {.value: 0x1.05200p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.05p+0"}, // Lsb 1, Round 0 and Trailing 1 in same hexit
94 {.value: 0x1.05800p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.06p+0"}, // Lsb 1, Round 1, Trailing 0
95 {.value: 0x1.05801p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.06p+0"}, // Lsb 1, Round 1 and Trailing 1 in different hexits
96 {.value: 0x1.05900p+0, .fmt: chars_format::hex, .precision: 2, .correct: "1.06p+0"}, // Lsb 1, Round 1 and Trailing 1 in same hexit
97
98 // Test carry propagation.
99 {.value: 0x1.0affffffffffep+0, .fmt: chars_format::hex, .precision: 12, .correct: "1.0b0000000000p+0"},
100
101 // Test carry propagation into the leading hexit.
102 {.value: 0x0.fffffffffffffp-1022, .fmt: chars_format::hex, .precision: 12, .correct: "1.000000000000p-1022"},
103 {.value: 0x1.fffffffffffffp+1023, .fmt: chars_format::hex, .precision: 12, .correct: "2.000000000000p+1023"},
104
105 // Test how the leading hexit participates in the rounding decision.
106 {.value: 0x0.000p+0, .fmt: chars_format::hex, .precision: 0, .correct: "0p+0"},
107 {.value: 0x0.001p-1022, .fmt: chars_format::hex, .precision: 0, .correct: "0p-1022"},
108 {.value: 0x0.200p-1022, .fmt: chars_format::hex, .precision: 0, .correct: "0p-1022"},
109 {.value: 0x0.800p-1022, .fmt: chars_format::hex, .precision: 0, .correct: "0p-1022"},
110 {.value: 0x0.801p-1022, .fmt: chars_format::hex, .precision: 0, .correct: "1p-1022"},
111 {.value: 0x0.900p-1022, .fmt: chars_format::hex, .precision: 0, .correct: "1p-1022"},
112 {.value: 0x1.000p+0, .fmt: chars_format::hex, .precision: 0, .correct: "1p+0"},
113 {.value: 0x1.001p+0, .fmt: chars_format::hex, .precision: 0, .correct: "1p+0"},
114 {.value: 0x1.200p+0, .fmt: chars_format::hex, .precision: 0, .correct: "1p+0"},
115 {.value: 0x1.800p+0, .fmt: chars_format::hex, .precision: 0, .correct: "2p+0"},
116 {.value: 0x1.801p+0, .fmt: chars_format::hex, .precision: 0, .correct: "2p+0"},
117 {.value: 0x1.900p+0, .fmt: chars_format::hex, .precision: 0, .correct: "2p+0"},
118};
119
120#endif // DOUBLE_HEX_PRECISION_TO_CHARS_TEST_CASES_HPP
121

source code of libcxx/test/std/utilities/charconv/charconv.msvc/double_hex_precision_to_chars_test_cases.hpp