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 // float stof(const string& str, size_t *idx = 0);
12 // float stof(const wstring& str, size_t *idx = 0);
19 #include "test_macros.h"
21 int main(int, char**) {
22 assert(std::stof("0") == 0);
23 assert(std::stof("-0") == 0);
24 assert(std::stof("-10") == -10);
25 assert(std::stof(" 10") == 10);
28 assert(std::stof("10g", &idx
) == 10);
33 assert(std::stof("INF", &idx
) == INFINITY
);
38 assert(std::isnan(std::stof("NAN", &idx
)));
41 #ifndef TEST_HAS_NO_EXCEPTIONS
45 assert(std::stof("1.e60", &idx
) == INFINITY
);
47 } catch (const std::out_of_range
&) {
54 assert(std::stof("1.e360", &idx
) == INFINITY
);
56 } catch (const std::out_of_range
&) {
63 (void)std::stof("", &idx
);
65 } catch (const std::invalid_argument
&) {
72 (void)std::stof(" - 8", &idx
);
74 } catch (const std::invalid_argument
&) {
81 (void)std::stof("a1", &idx
);
83 } catch (const std::invalid_argument
&) {
87 #endif // TEST_HAS_NO_EXCEPTIONS
89 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
90 assert(std::stof(L
"0") == 0);
91 assert(std::stof(L
"-0") == 0);
92 assert(std::stof(L
"-10.5") == -10.5);
93 assert(std::stof(L
" 10") == 10);
96 assert(std::stof(L
"10g", &idx
) == 10);
101 assert(std::stof(L
"INF", &idx
) == INFINITY
);
106 assert(std::isnan(std::stof(L
"NAN", &idx
)));
109 # ifndef TEST_HAS_NO_EXCEPTIONS
113 assert(std::stof(L
"1.e60", &idx
) == INFINITY
);
115 } catch (const std::out_of_range
&) {
122 assert(std::stof(L
"1.e360", &idx
) == INFINITY
);
124 } catch (const std::out_of_range
&) {
131 (void)std::stof(L
"", &idx
);
133 } catch (const std::invalid_argument
&) {
140 (void)std::stof(L
" - 8", &idx
);
142 } catch (const std::invalid_argument
&) {
149 (void)std::stof(L
"a1", &idx
);
151 } catch (const std::invalid_argument
&) {
155 # endif // TEST_HAS_NO_EXCEPTIONS
156 #endif // TEST_HAS_NO_WIDE_CHARACTERS