[TableGen][SystemZ] Correctly check the range of a leaf immediate (#119931)
[llvm-project.git] / libcxx / test / std / strings / string.conversions / stold.pass.cpp
blobef756982ee9a03657cde0f12380af50b1ca5bf45
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // long double stold(const string& str, size_t *idx = 0);
12 // long double stold(const wstring& str, size_t *idx = 0);
14 #include <cassert>
15 #include <cmath>
16 #include <stdexcept>
17 #include <string>
19 #include "test_macros.h"
21 int main(int, char**) {
22 assert(std::stold("0") == 0);
23 assert(std::stold("-0") == 0);
24 assert(std::stold("-10") == -10);
25 assert(std::stold(" 10") == 10);
27 std::size_t idx = 0;
28 assert(std::stold("10g", &idx) == 10);
29 assert(idx == 2);
32 std::size_t idx = 0;
33 assert(std::stold("1.e60", &idx) == 1.e60L);
34 assert(idx == 5);
37 std::size_t idx = 0;
38 assert(std::stold("INF", &idx) == INFINITY);
39 assert(idx == 3);
42 std::size_t idx = 0;
43 assert(std::isnan(std::stold("NAN", &idx)));
44 assert(idx == 3);
47 #ifndef TEST_HAS_NO_EXCEPTIONS
49 std::size_t idx = 0;
50 try {
51 (void)std::stold("", &idx);
52 assert(false);
53 } catch (const std::invalid_argument&) {
54 assert(idx == 0);
58 std::size_t idx = 0;
59 try {
60 (void)std::stold(" - 8", &idx);
61 assert(false);
62 } catch (const std::invalid_argument&) {
63 assert(idx == 0);
67 std::size_t idx = 0;
68 try {
69 (void)std::stold("a1", &idx);
70 assert(false);
71 } catch (const std::invalid_argument&) {
72 assert(idx == 0);
76 std::size_t idx = 0;
77 try {
78 assert(std::stold("1.e6000", &idx) == INFINITY);
79 assert(false);
80 } catch (const std::out_of_range&) {
81 assert(idx == 0);
84 #endif // TEST_HAS_NO_EXCEPTIONS
86 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
87 assert(std::stold(L"0") == 0);
88 assert(std::stold(L"-0") == 0);
89 assert(std::stold(L"-10.5") == -10.5);
90 assert(std::stold(L" 10") == 10);
92 std::size_t idx = 0;
93 assert(std::stold(L"10g", &idx) == 10);
94 assert(idx == 2);
97 std::size_t idx = 0;
98 assert(std::stold(L"1.e60", &idx) == 1.e60L);
99 assert(idx == 5);
102 std::size_t idx = 0;
103 assert(std::stold(L"INF", &idx) == INFINITY);
104 assert(idx == 3);
107 std::size_t idx = 0;
108 assert(std::isnan(std::stold(L"NAN", &idx)));
109 assert(idx == 3);
111 # ifndef TEST_HAS_NO_EXCEPTIONS
113 std::size_t idx = 0;
114 try {
115 (void)std::stold(L"", &idx);
116 assert(false);
117 } catch (const std::invalid_argument&) {
118 assert(idx == 0);
122 std::size_t idx = 0;
123 try {
124 (void)std::stold(L" - 8", &idx);
125 assert(false);
126 } catch (const std::invalid_argument&) {
127 assert(idx == 0);
131 std::size_t idx = 0;
132 try {
133 (void)std::stold(L"a1", &idx);
134 assert(false);
135 } catch (const std::invalid_argument&) {
136 assert(idx == 0);
140 std::size_t idx = 0;
141 try {
142 assert(std::stold(L"1.e6000", &idx) == INFINITY);
143 assert(false);
144 } catch (const std::out_of_range&) {
145 assert(idx == 0);
148 # endif // TEST_HAS_NO_EXCEPTIONS
149 #endif // TEST_HAS_NO_WIDE_CHARACTERS
151 return 0;