[AMDGPU] Mark AGPR tuple implicit in the first instr of AGPR spills. (#115285)
[llvm-project.git] / libcxx / test / std / strings / string.conversions / stof.pass.cpp
blob4ddeb8f95ede03813cbdd93444f68dce272687f5
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 // float stof(const string& str, size_t *idx = 0);
12 // float stof(const wstring& str, size_t *idx = 0);
14 #include <string>
15 #include <cmath>
16 #include <cassert>
17 #include <stdexcept>
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);
27 std::size_t idx = 0;
28 assert(std::stof("10g", &idx) == 10);
29 assert(idx == 2);
32 std::size_t idx = 0;
33 assert(std::stof("INF", &idx) == INFINITY);
34 assert(idx == 3);
37 std::size_t idx = 0;
38 assert(std::isnan(std::stof("NAN", &idx)));
39 assert(idx == 3);
41 #ifndef TEST_HAS_NO_EXCEPTIONS
43 std::size_t idx = 0;
44 try {
45 assert(std::stof("1.e60", &idx) == INFINITY);
46 assert(false);
47 } catch (const std::out_of_range&) {
48 assert(idx == 0);
52 std::size_t idx = 0;
53 try {
54 assert(std::stof("1.e360", &idx) == INFINITY);
55 assert(false);
56 } catch (const std::out_of_range&) {
57 assert(idx == 0);
61 std::size_t idx = 0;
62 try {
63 (void)std::stof("", &idx);
64 assert(false);
65 } catch (const std::invalid_argument&) {
66 assert(idx == 0);
70 std::size_t idx = 0;
71 try {
72 (void)std::stof(" - 8", &idx);
73 assert(false);
74 } catch (const std::invalid_argument&) {
75 assert(idx == 0);
79 std::size_t idx = 0;
80 try {
81 (void)std::stof("a1", &idx);
82 assert(false);
83 } catch (const std::invalid_argument&) {
84 assert(idx == 0);
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);
95 std::size_t idx = 0;
96 assert(std::stof(L"10g", &idx) == 10);
97 assert(idx == 2);
100 std::size_t idx = 0;
101 assert(std::stof(L"INF", &idx) == INFINITY);
102 assert(idx == 3);
105 std::size_t idx = 0;
106 assert(std::isnan(std::stof(L"NAN", &idx)));
107 assert(idx == 3);
109 # ifndef TEST_HAS_NO_EXCEPTIONS
111 std::size_t idx = 0;
112 try {
113 assert(std::stof(L"1.e60", &idx) == INFINITY);
114 assert(false);
115 } catch (const std::out_of_range&) {
116 assert(idx == 0);
120 std::size_t idx = 0;
121 try {
122 assert(std::stof(L"1.e360", &idx) == INFINITY);
123 assert(false);
124 } catch (const std::out_of_range&) {
125 assert(idx == 0);
129 std::size_t idx = 0;
130 try {
131 (void)std::stof(L"", &idx);
132 assert(false);
133 } catch (const std::invalid_argument&) {
134 assert(idx == 0);
138 std::size_t idx = 0;
139 try {
140 (void)std::stof(L" - 8", &idx);
141 assert(false);
142 } catch (const std::invalid_argument&) {
143 assert(idx == 0);
147 std::size_t idx = 0;
148 try {
149 (void)std::stof(L"a1", &idx);
150 assert(false);
151 } catch (const std::invalid_argument&) {
152 assert(idx == 0);
155 # endif // TEST_HAS_NO_EXCEPTIONS
156 #endif // TEST_HAS_NO_WIDE_CHARACTERS
158 return 0;