1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // long double stold(const string& str, size_t *idx = 0);
12 // long double stold(const wstring& str, size_t *idx = 0);
19 #include "test_macros.h"
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);
32 assert(std::stold("10g", &idx
) == 10);
35 assert(std::stold(L
"10g", &idx
) == 10);
37 #ifndef TEST_HAS_NO_EXCEPTIONS
41 assert(std::stold("1.e60", &idx
) == 1.e60L
);
44 #ifndef TEST_HAS_NO_EXCEPTIONS
45 catch (const std::out_of_range
&)
52 assert(std::stold(L
"1.e60", &idx
) == 1.e60L
);
55 #ifndef TEST_HAS_NO_EXCEPTIONS
56 catch (const std::out_of_range
&)
62 #ifndef TEST_HAS_NO_EXCEPTIONS
65 assert(std::stold("1.e6000", &idx
) == INFINITY
);
68 catch (const std::out_of_range
&)
74 assert(std::stold(L
"1.e6000", &idx
) == INFINITY
);
77 catch (const std::out_of_range
&)
84 assert(std::stold("INF", &idx
) == INFINITY
);
87 #ifndef TEST_HAS_NO_EXCEPTIONS
88 catch (const std::out_of_range
&)
94 #ifndef TEST_HAS_NO_EXCEPTIONS
98 assert(std::stold(L
"INF", &idx
) == INFINITY
);
101 #ifndef TEST_HAS_NO_EXCEPTIONS
102 catch (const std::out_of_range
&)
108 #ifndef TEST_HAS_NO_EXCEPTIONS
112 assert(std::isnan(std::stold("NAN", &idx
)));
115 #ifndef TEST_HAS_NO_EXCEPTIONS
116 catch (const std::out_of_range
&)
122 #ifndef TEST_HAS_NO_EXCEPTIONS
126 assert(std::isnan(std::stold(L
"NAN", &idx
)));
129 #ifndef TEST_HAS_NO_EXCEPTIONS
130 catch (const std::out_of_range
&)
137 std::stold("", &idx
);
140 catch (const std::invalid_argument
&)
146 std::stold(L
"", &idx
);
149 catch (const std::invalid_argument
&)
155 std::stold(" - 8", &idx
);
158 catch (const std::invalid_argument
&)
164 std::stold(L
" - 8", &idx
);
167 catch (const std::invalid_argument
&)
173 std::stold("a1", &idx
);
176 catch (const std::invalid_argument
&)
182 std::stold(L
"a1", &idx
);
185 catch (const std::invalid_argument
&)