Remove building with NOCRYPTO option
[minix.git] / external / bsd / libc++ / dist / libcxx / test / strings / string.conversions / stof.pass.cpp
blob65809cb2cf11dee8e0084526ef26370bb1f174df
1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // XFAIL: with_system_lib=x86_64-apple-darwin11
11 // XFAIL: with_system_lib=x86_64-apple-darwin12
13 // <string>
15 // float stof(const string& str, size_t *idx = 0);
16 // float stof(const wstring& str, size_t *idx = 0);
18 #include <string>
19 #include <cmath>
20 #include <cassert>
22 int main()
24 assert(std::stof("0") == 0);
25 assert(std::stof(L"0") == 0);
26 assert(std::stof("-0") == 0);
27 assert(std::stof(L"-0") == 0);
28 assert(std::stof("-10") == -10);
29 assert(std::stof(L"-10.5") == -10.5);
30 assert(std::stof(" 10") == 10);
31 assert(std::stof(L" 10") == 10);
32 size_t idx = 0;
33 assert(std::stof("10g", &idx) == 10);
34 assert(idx == 2);
35 idx = 0;
36 assert(std::stof(L"10g", &idx) == 10);
37 assert(idx == 2);
38 idx = 0;
39 try
41 assert(std::stof("1.e60", &idx) == INFINITY);
42 assert(false);
44 catch (const std::out_of_range&)
46 assert(idx == 0);
48 try
50 assert(std::stof(L"1.e60", &idx) == INFINITY);
51 assert(false);
53 catch (const std::out_of_range&)
55 assert(idx == 0);
57 idx = 0;
58 try
60 assert(std::stof("1.e360", &idx) == INFINITY);
61 assert(false);
63 catch (const std::out_of_range&)
65 assert(idx == 0);
67 try
69 assert(std::stof(L"1.e360", &idx) == INFINITY);
70 assert(false);
72 catch (const std::out_of_range&)
74 assert(idx == 0);
76 try
78 assert(std::stof("INF", &idx) == INFINITY);
79 assert(idx == 3);
81 catch (const std::out_of_range&)
83 assert(false);
85 idx = 0;
86 try
88 assert(std::stof(L"INF", &idx) == INFINITY);
89 assert(idx == 3);
91 catch (const std::out_of_range&)
93 assert(false);
95 idx = 0;
96 try
98 assert(std::isnan(std::stof("NAN", &idx)));
99 assert(idx == 3);
101 catch (const std::out_of_range&)
103 assert(false);
105 idx = 0;
108 assert(std::isnan(std::stof(L"NAN", &idx)));
109 assert(idx == 3);
111 catch (const std::out_of_range&)
113 assert(false);
115 idx = 0;
118 std::stof("", &idx);
119 assert(false);
121 catch (const std::invalid_argument&)
123 assert(idx == 0);
127 std::stof(L"", &idx);
128 assert(false);
130 catch (const std::invalid_argument&)
132 assert(idx == 0);
136 std::stof(" - 8", &idx);
137 assert(false);
139 catch (const std::invalid_argument&)
141 assert(idx == 0);
145 std::stof(L" - 8", &idx);
146 assert(false);
148 catch (const std::invalid_argument&)
150 assert(idx == 0);
154 std::stof("a1", &idx);
155 assert(false);
157 catch (const std::invalid_argument&)
159 assert(idx == 0);
163 std::stof(L"a1", &idx);
164 assert(false);
166 catch (const std::invalid_argument&)
168 assert(idx == 0);