Remove building with NOCRYPTO option
[minix.git] / external / bsd / libc++ / dist / libcxx / test / strings / string.conversions / stold.pass.cpp
blob93c59fe09a11fd18228a9093da95f42d784c03e0
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 //===----------------------------------------------------------------------===//
10 // <string>
12 // long double stold(const string& str, size_t *idx = 0);
13 // long double stold(const wstring& str, size_t *idx = 0);
15 #include <iostream>
17 #include <string>
18 #include <cmath>
19 #include <cassert>
21 int main()
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);
31 size_t idx = 0;
32 assert(std::stold("10g", &idx) == 10);
33 assert(idx == 2);
34 idx = 0;
35 assert(std::stold(L"10g", &idx) == 10);
36 assert(idx == 2);
37 try
39 assert(std::stold("1.e60", &idx) == 1.e60L);
40 assert(idx == 5);
42 catch (const std::out_of_range&)
44 assert(false);
46 try
48 assert(std::stold(L"1.e60", &idx) == 1.e60L);
49 assert(idx == 5);
51 catch (const std::out_of_range&)
53 assert(false);
55 idx = 0;
56 try
58 assert(std::stold("1.e6000", &idx) == INFINITY);
59 assert(false);
61 catch (const std::out_of_range&)
63 assert(idx == 0);
65 try
67 assert(std::stold(L"1.e6000", &idx) == INFINITY);
68 assert(false);
70 catch (const std::out_of_range&)
72 assert(idx == 0);
74 try
76 assert(std::stold("INF", &idx) == INFINITY);
77 assert(idx == 3);
79 catch (const std::out_of_range&)
81 assert(false);
83 idx = 0;
84 try
86 assert(std::stold(L"INF", &idx) == INFINITY);
87 assert(idx == 3);
89 catch (const std::out_of_range&)
91 assert(false);
93 idx = 0;
94 try
96 assert(std::isnan(std::stold("NAN", &idx)));
97 assert(idx == 3);
99 catch (const std::out_of_range&)
101 assert(false);
103 idx = 0;
106 assert(std::isnan(std::stold(L"NAN", &idx)));
107 assert(idx == 3);
109 catch (const std::out_of_range&)
111 assert(false);
113 idx = 0;
116 std::stold("", &idx);
117 assert(false);
119 catch (const std::invalid_argument&)
121 assert(idx == 0);
125 std::stold(L"", &idx);
126 assert(false);
128 catch (const std::invalid_argument&)
130 assert(idx == 0);
134 std::stold(" - 8", &idx);
135 assert(false);
137 catch (const std::invalid_argument&)
139 assert(idx == 0);
143 std::stold(L" - 8", &idx);
144 assert(false);
146 catch (const std::invalid_argument&)
148 assert(idx == 0);
152 std::stold("a1", &idx);
153 assert(false);
155 catch (const std::invalid_argument&)
157 assert(idx == 0);
161 std::stold(L"a1", &idx);
162 assert(false);
164 catch (const std::invalid_argument&)
166 assert(idx == 0);