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