Remove building with NOCRYPTO option
[minix.git] / external / bsd / libc++ / dist / libcxx / test / strings / string.conversions / stod.pass.cpp
blob026d2301e07106de40c4665e6a1a2fdb3924a8d3
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 // double stod(const string& str, size_t *idx = 0);
13 // double stod(const wstring& str, size_t *idx = 0);
15 #include <string>
16 #include <cmath>
17 #include <cassert>
19 int main()
21 assert(std::stod("0") == 0);
22 assert(std::stod(L"0") == 0);
23 assert(std::stod("-0") == 0);
24 assert(std::stod(L"-0") == 0);
25 assert(std::stod("-10") == -10);
26 assert(std::stod(L"-10.5") == -10.5);
27 assert(std::stod(" 10") == 10);
28 assert(std::stod(L" 10") == 10);
29 size_t idx = 0;
30 assert(std::stod("10g", &idx) == 10);
31 assert(idx == 2);
32 idx = 0;
33 assert(std::stod(L"10g", &idx) == 10);
34 assert(idx == 2);
35 try
37 assert(std::stod("1.e60", &idx) == 1.e60);
38 assert(idx == 5);
40 catch (const std::out_of_range&)
42 assert(false);
44 try
46 assert(std::stod(L"1.e60", &idx) == 1.e60);
47 assert(idx == 5);
49 catch (const std::out_of_range&)
51 assert(false);
53 idx = 0;
54 try
56 assert(std::stod("1.e360", &idx) == INFINITY);
57 assert(false);
59 catch (const std::out_of_range&)
61 assert(idx == 0);
63 try
65 assert(std::stod(L"1.e360", &idx) == INFINITY);
66 assert(false);
68 catch (const std::out_of_range&)
70 assert(idx == 0);
72 try
74 assert(std::stod("INF", &idx) == INFINITY);
75 assert(idx == 3);
77 catch (const std::out_of_range&)
79 assert(false);
81 idx = 0;
82 try
84 assert(std::stod(L"INF", &idx) == INFINITY);
85 assert(idx == 3);
87 catch (const std::out_of_range&)
89 assert(false);
91 idx = 0;
92 try
94 assert(std::isnan(std::stod("NAN", &idx)));
95 assert(idx == 3);
97 catch (const std::out_of_range&)
99 assert(false);
101 idx = 0;
104 assert(std::isnan(std::stod(L"NAN", &idx)));
105 assert(idx == 3);
107 catch (const std::out_of_range&)
109 assert(false);
111 idx = 0;
114 std::stod("", &idx);
115 assert(false);
117 catch (const std::invalid_argument&)
119 assert(idx == 0);
123 std::stod(L"", &idx);
124 assert(false);
126 catch (const std::invalid_argument&)
128 assert(idx == 0);
132 std::stod(" - 8", &idx);
133 assert(false);
135 catch (const std::invalid_argument&)
137 assert(idx == 0);
141 std::stod(L" - 8", &idx);
142 assert(false);
144 catch (const std::invalid_argument&)
146 assert(idx == 0);
150 std::stod("a1", &idx);
151 assert(false);
153 catch (const std::invalid_argument&)
155 assert(idx == 0);
159 std::stod(L"a1", &idx);
160 assert(false);
162 catch (const std::invalid_argument&)
164 assert(idx == 0);