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
|
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef FLOAT_FROM_CHARS_TEST_CASES_HPP
#define FLOAT_FROM_CHARS_TEST_CASES_HPP
#include <charconv>
#include <stddef.h>
#include <system_error>
using namespace std;
inline constexpr FloatFromCharsTestCase float_from_chars_test_cases[] = {
{"1.a0000400", chars_format::hex, 10, errc{}, 0x1.a00004p0f}, // exact
{"1.a0000401", chars_format::hex, 10, errc{}, 0x1.a00004p0f}, // below midpoint, round down
{"1.a0000500", chars_format::hex, 10, errc{}, 0x1.a00004p0f}, // midpoint, round down to even
{"1.a0000501", chars_format::hex, 10, errc{}, 0x1.a00006p0f}, // above midpoint, round up
{"1.a0000600", chars_format::hex, 10, errc{}, 0x1.a00006p0f}, // exact
{"1.a0000601", chars_format::hex, 10, errc{}, 0x1.a00006p0f}, // below midpoint, round down
{"1.a0000700", chars_format::hex, 10, errc{}, 0x1.a00008p0f}, // midpoint, round up to even
{"1.a0000701", chars_format::hex, 10, errc{}, 0x1.a00008p0f}, // above midpoint, round up
{"1.0000040", chars_format::hex, 9, errc{}, 0x1.000004p0f}, // exact
{"1.0000041", chars_format::hex, 9, errc{}, 0x1.000004p0f}, // below midpoint, round down
{"1.0000050", chars_format::hex, 9, errc{}, 0x1.000004p0f}, // midpoint, round down to even
{"1.0000051", chars_format::hex, 9, errc{}, 0x1.000006p0f}, // above midpoint, round up
{"1.0000060", chars_format::hex, 9, errc{}, 0x1.000006p0f}, // exact
{"1.0000061", chars_format::hex, 9, errc{}, 0x1.000006p0f}, // below midpoint, round down
{"1.0000070", chars_format::hex, 9, errc{}, 0x1.000008p0f}, // midpoint, round up to even
{"1.0000071", chars_format::hex, 9, errc{}, 0x1.000008p0f}, // above midpoint, round up
{"1.0000002384185791015625000000", chars_format::general, 30, errc{}, 0x1.000004p0f}, // exact
{"1.0000002421438694000244140625", chars_format::general, 30, errc{}, 0x1.000004p0f}, // below midpoint, round down
{"1.0000002980232238769531249999", chars_format::general, 30, errc{}, 0x1.000004p0f}, // below midpoint, round down
{"1.0000002980232238769531250000", chars_format::general, 30, errc{},
0x1.000004p0f}, // midpoint, round down to even
{"1.0000002980232238769531250001", chars_format::general, 30, errc{}, 0x1.000006p0f}, // above midpoint, round up
{"1.0000003017485141754150390625", chars_format::general, 30, errc{}, 0x1.000006p0f}, // above midpoint, round up
{"1.0000003576278686523437500000", chars_format::general, 30, errc{}, 0x1.000006p0f}, // exact
{"1.0000003613531589508056640625", chars_format::general, 30, errc{}, 0x1.000006p0f}, // below midpoint, round down
{"1.0000004172325134277343749999", chars_format::general, 30, errc{}, 0x1.000006p0f}, // below midpoint, round down
{"1.0000004172325134277343750000", chars_format::general, 30, errc{}, 0x1.000008p0f}, // midpoint, round up to even
{"1.0000004172325134277343750001", chars_format::general, 30, errc{}, 0x1.000008p0f}, // above midpoint, round up
{"1.0000004209578037261962890625", chars_format::general, 30, errc{}, 0x1.000008p0f}, // above midpoint, round up
// VSO-838635 "<charconv>: from_chars() mishandles certain subnormals"
// This bug didn't actually affect float, but we should have similar test cases.
// These values change on half-ulp boundaries:
// 1 * 2^-150 ~= 7.01e-46 (half-ulp between zero and min subnormal)
// 2 * 2^-150 ~= 1.40e-45 (min subnormal)
// 3 * 2^-150 ~= 2.10e-45 (half-ulp between min subnormal and next subnormal)
// 4 * 2^-150 ~= 2.80e-45 (next subnormal)
{"6."
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
"6666666666666666666e-46",
chars_format::scientific, 1006, errc::result_out_of_range, 0x0.000000p+0f},
{"7."
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
"7777777777777777777e-46",
chars_format::scientific, 1006, errc{}, 0x0.000002p-126f},
{"8."
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
"8888888888888888888e-46",
chars_format::scientific, 1006, errc{}, 0x0.000002p-126f},
{"9."
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
"9999999999999999999e-46",
chars_format::scientific, 1006, errc{}, 0x0.000002p-126f},
{"1."
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111e-45",
chars_format::scientific, 1006, errc{}, 0x0.000002p-126f},
{"2."
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
"2222222222222222222e-45",
chars_format::scientific, 1006, errc{}, 0x0.000004p-126f},
// VSO-733765 "<charconv>: [Feedback] double std::from_chars behavior on exponent out of range"
// LWG-3081 "Floating point from_chars API does not distinguish between overflow and underflow"
// These test cases exercise every overflow/underflow codepath.
{"1e+1000", chars_format::scientific, 7, errc::result_out_of_range, float_inf},
{"1e-1000", chars_format::scientific, 7, errc::result_out_of_range, 0.0f},
{"1.ffffffp+127", chars_format::hex, 13, errc::result_out_of_range, float_inf},
{"1e+2000", chars_format::scientific, 7, errc::result_out_of_range, float_inf},
{"1e-2000", chars_format::scientific, 7, errc::result_out_of_range, 0.0f},
{"1e+9999", chars_format::scientific, 7, errc::result_out_of_range, float_inf},
{"1e-9999", chars_format::scientific, 7, errc::result_out_of_range, 0.0f},
{"10e+5199", chars_format::scientific, 8, errc::result_out_of_range, float_inf},
{"0.001e-5199", chars_format::scientific, 11, errc::result_out_of_range, 0.0f},
};
#endif // FLOAT_FROM_CHARS_TEST_CASES_HPP
|