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"
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);
28 assert(std::stold("10g", &idx
) == 10);
33 assert(std::stold("1.e60", &idx
) == 1.e60L
);
38 assert(std::stold("INF", &idx
) == INFINITY
);
43 assert(std::isnan(std::stold("NAN", &idx
)));
47 #ifndef TEST_HAS_NO_EXCEPTIONS
51 (void)std::stold("", &idx
);
53 } catch (const std::invalid_argument
&) {
60 (void)std::stold(" - 8", &idx
);
62 } catch (const std::invalid_argument
&) {
69 (void)std::stold("a1", &idx
);
71 } catch (const std::invalid_argument
&) {
78 assert(std::stold("1.e6000", &idx
) == INFINITY
);
80 } catch (const std::out_of_range
&) {
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);
93 assert(std::stold(L
"10g", &idx
) == 10);
98 assert(std::stold(L
"1.e60", &idx
) == 1.e60L
);
103 assert(std::stold(L
"INF", &idx
) == INFINITY
);
108 assert(std::isnan(std::stold(L
"NAN", &idx
)));
111 # ifndef TEST_HAS_NO_EXCEPTIONS
115 (void)std::stold(L
"", &idx
);
117 } catch (const std::invalid_argument
&) {
124 (void)std::stold(L
" - 8", &idx
);
126 } catch (const std::invalid_argument
&) {
133 (void)std::stold(L
"a1", &idx
);
135 } catch (const std::invalid_argument
&) {
142 assert(std::stold(L
"1.e6000", &idx
) == INFINITY
);
144 } catch (const std::out_of_range
&) {
148 # endif // TEST_HAS_NO_EXCEPTIONS
149 #endif // TEST_HAS_NO_WIDE_CHARACTERS