[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / string.conversions / stold.pass.cpp
blob4b1b1b1292d18f3c2f03bdad165a6486d93c1499
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**)
23 assert(std::stold("0") == 0);
24 assert(std::stold(L"0") == 0);
25 assert(std::stold("-0") == 0);
26 assert(std::stold(L"-0") == 0);
27 assert(std::stold("-10") == -10);
28 assert(std::stold(L"-10.5") == -10.5);
29 assert(std::stold(" 10") == 10);
30 assert(std::stold(L" 10") == 10);
31 size_t idx = 0;
32 assert(std::stold("10g", &idx) == 10);
33 assert(idx == 2);
34 idx = 0;
35 assert(std::stold(L"10g", &idx) == 10);
36 assert(idx == 2);
37 #ifndef TEST_HAS_NO_EXCEPTIONS
38 try
39 #endif
41 assert(std::stold("1.e60", &idx) == 1.e60L);
42 assert(idx == 5);
44 #ifndef TEST_HAS_NO_EXCEPTIONS
45 catch (const std::out_of_range&)
47 assert(false);
49 try
50 #endif
52 assert(std::stold(L"1.e60", &idx) == 1.e60L);
53 assert(idx == 5);
55 #ifndef TEST_HAS_NO_EXCEPTIONS
56 catch (const std::out_of_range&)
58 assert(false);
60 #endif
61 idx = 0;
62 #ifndef TEST_HAS_NO_EXCEPTIONS
63 try
65 assert(std::stold("1.e6000", &idx) == INFINITY);
66 assert(false);
68 catch (const std::out_of_range&)
70 assert(idx == 0);
72 try
74 assert(std::stold(L"1.e6000", &idx) == INFINITY);
75 assert(false);
77 catch (const std::out_of_range&)
79 assert(idx == 0);
81 try
82 #endif
84 assert(std::stold("INF", &idx) == INFINITY);
85 assert(idx == 3);
87 #ifndef TEST_HAS_NO_EXCEPTIONS
88 catch (const std::out_of_range&)
90 assert(false);
92 #endif
93 idx = 0;
94 #ifndef TEST_HAS_NO_EXCEPTIONS
95 try
96 #endif
98 assert(std::stold(L"INF", &idx) == INFINITY);
99 assert(idx == 3);
101 #ifndef TEST_HAS_NO_EXCEPTIONS
102 catch (const std::out_of_range&)
104 assert(false);
106 #endif
107 idx = 0;
108 #ifndef TEST_HAS_NO_EXCEPTIONS
110 #endif
112 assert(std::isnan(std::stold("NAN", &idx)));
113 assert(idx == 3);
115 #ifndef TEST_HAS_NO_EXCEPTIONS
116 catch (const std::out_of_range&)
118 assert(false);
120 #endif
121 idx = 0;
122 #ifndef TEST_HAS_NO_EXCEPTIONS
124 #endif
126 assert(std::isnan(std::stold(L"NAN", &idx)));
127 assert(idx == 3);
129 #ifndef TEST_HAS_NO_EXCEPTIONS
130 catch (const std::out_of_range&)
132 assert(false);
134 idx = 0;
137 std::stold("", &idx);
138 assert(false);
140 catch (const std::invalid_argument&)
142 assert(idx == 0);
146 std::stold(L"", &idx);
147 assert(false);
149 catch (const std::invalid_argument&)
151 assert(idx == 0);
155 std::stold(" - 8", &idx);
156 assert(false);
158 catch (const std::invalid_argument&)
160 assert(idx == 0);
164 std::stold(L" - 8", &idx);
165 assert(false);
167 catch (const std::invalid_argument&)
169 assert(idx == 0);
173 std::stold("a1", &idx);
174 assert(false);
176 catch (const std::invalid_argument&)
178 assert(idx == 0);
182 std::stold(L"a1", &idx);
183 assert(false);
185 catch (const std::invalid_argument&)
187 assert(idx == 0);
189 #endif
191 return 0;