1*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
2*58b9f456SAndroid Build Coastguard Worker //
3*58b9f456SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*58b9f456SAndroid Build Coastguard Worker //
5*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*58b9f456SAndroid Build Coastguard Worker //
8*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*58b9f456SAndroid Build Coastguard Worker
10*58b9f456SAndroid Build Coastguard Worker // <string>
11*58b9f456SAndroid Build Coastguard Worker
12*58b9f456SAndroid Build Coastguard Worker // long double stold(const string& str, size_t *idx = 0);
13*58b9f456SAndroid Build Coastguard Worker // long double stold(const wstring& str, size_t *idx = 0);
14*58b9f456SAndroid Build Coastguard Worker
15*58b9f456SAndroid Build Coastguard Worker #include <iostream>
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Worker #include <string>
18*58b9f456SAndroid Build Coastguard Worker #include <cmath>
19*58b9f456SAndroid Build Coastguard Worker #include <cassert>
20*58b9f456SAndroid Build Coastguard Worker
21*58b9f456SAndroid Build Coastguard Worker #include "test_macros.h"
22*58b9f456SAndroid Build Coastguard Worker
main()23*58b9f456SAndroid Build Coastguard Worker int main()
24*58b9f456SAndroid Build Coastguard Worker {
25*58b9f456SAndroid Build Coastguard Worker assert(std::stold("0") == 0);
26*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L"0") == 0);
27*58b9f456SAndroid Build Coastguard Worker assert(std::stold("-0") == 0);
28*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L"-0") == 0);
29*58b9f456SAndroid Build Coastguard Worker assert(std::stold("-10") == -10);
30*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L"-10.5") == -10.5);
31*58b9f456SAndroid Build Coastguard Worker assert(std::stold(" 10") == 10);
32*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L" 10") == 10);
33*58b9f456SAndroid Build Coastguard Worker size_t idx = 0;
34*58b9f456SAndroid Build Coastguard Worker assert(std::stold("10g", &idx) == 10);
35*58b9f456SAndroid Build Coastguard Worker assert(idx == 2);
36*58b9f456SAndroid Build Coastguard Worker idx = 0;
37*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L"10g", &idx) == 10);
38*58b9f456SAndroid Build Coastguard Worker assert(idx == 2);
39*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
40*58b9f456SAndroid Build Coastguard Worker try
41*58b9f456SAndroid Build Coastguard Worker #endif
42*58b9f456SAndroid Build Coastguard Worker {
43*58b9f456SAndroid Build Coastguard Worker assert(std::stold("1.e60", &idx) == 1.e60L);
44*58b9f456SAndroid Build Coastguard Worker assert(idx == 5);
45*58b9f456SAndroid Build Coastguard Worker }
46*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
47*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
48*58b9f456SAndroid Build Coastguard Worker {
49*58b9f456SAndroid Build Coastguard Worker assert(false);
50*58b9f456SAndroid Build Coastguard Worker }
51*58b9f456SAndroid Build Coastguard Worker try
52*58b9f456SAndroid Build Coastguard Worker #endif
53*58b9f456SAndroid Build Coastguard Worker {
54*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L"1.e60", &idx) == 1.e60L);
55*58b9f456SAndroid Build Coastguard Worker assert(idx == 5);
56*58b9f456SAndroid Build Coastguard Worker }
57*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
58*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
59*58b9f456SAndroid Build Coastguard Worker {
60*58b9f456SAndroid Build Coastguard Worker assert(false);
61*58b9f456SAndroid Build Coastguard Worker }
62*58b9f456SAndroid Build Coastguard Worker #endif
63*58b9f456SAndroid Build Coastguard Worker idx = 0;
64*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
65*58b9f456SAndroid Build Coastguard Worker try
66*58b9f456SAndroid Build Coastguard Worker {
67*58b9f456SAndroid Build Coastguard Worker assert(std::stold("1.e6000", &idx) == INFINITY);
68*58b9f456SAndroid Build Coastguard Worker assert(false);
69*58b9f456SAndroid Build Coastguard Worker }
70*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
71*58b9f456SAndroid Build Coastguard Worker {
72*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
73*58b9f456SAndroid Build Coastguard Worker }
74*58b9f456SAndroid Build Coastguard Worker try
75*58b9f456SAndroid Build Coastguard Worker {
76*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L"1.e6000", &idx) == INFINITY);
77*58b9f456SAndroid Build Coastguard Worker assert(false);
78*58b9f456SAndroid Build Coastguard Worker }
79*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
80*58b9f456SAndroid Build Coastguard Worker {
81*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
82*58b9f456SAndroid Build Coastguard Worker }
83*58b9f456SAndroid Build Coastguard Worker try
84*58b9f456SAndroid Build Coastguard Worker #endif
85*58b9f456SAndroid Build Coastguard Worker {
86*58b9f456SAndroid Build Coastguard Worker assert(std::stold("INF", &idx) == INFINITY);
87*58b9f456SAndroid Build Coastguard Worker assert(idx == 3);
88*58b9f456SAndroid Build Coastguard Worker }
89*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
90*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
91*58b9f456SAndroid Build Coastguard Worker {
92*58b9f456SAndroid Build Coastguard Worker assert(false);
93*58b9f456SAndroid Build Coastguard Worker }
94*58b9f456SAndroid Build Coastguard Worker #endif
95*58b9f456SAndroid Build Coastguard Worker idx = 0;
96*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
97*58b9f456SAndroid Build Coastguard Worker try
98*58b9f456SAndroid Build Coastguard Worker #endif
99*58b9f456SAndroid Build Coastguard Worker {
100*58b9f456SAndroid Build Coastguard Worker assert(std::stold(L"INF", &idx) == INFINITY);
101*58b9f456SAndroid Build Coastguard Worker assert(idx == 3);
102*58b9f456SAndroid Build Coastguard Worker }
103*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
104*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
105*58b9f456SAndroid Build Coastguard Worker {
106*58b9f456SAndroid Build Coastguard Worker assert(false);
107*58b9f456SAndroid Build Coastguard Worker }
108*58b9f456SAndroid Build Coastguard Worker #endif
109*58b9f456SAndroid Build Coastguard Worker idx = 0;
110*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
111*58b9f456SAndroid Build Coastguard Worker try
112*58b9f456SAndroid Build Coastguard Worker #endif
113*58b9f456SAndroid Build Coastguard Worker {
114*58b9f456SAndroid Build Coastguard Worker assert(std::isnan(std::stold("NAN", &idx)));
115*58b9f456SAndroid Build Coastguard Worker assert(idx == 3);
116*58b9f456SAndroid Build Coastguard Worker }
117*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
118*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
119*58b9f456SAndroid Build Coastguard Worker {
120*58b9f456SAndroid Build Coastguard Worker assert(false);
121*58b9f456SAndroid Build Coastguard Worker }
122*58b9f456SAndroid Build Coastguard Worker #endif
123*58b9f456SAndroid Build Coastguard Worker idx = 0;
124*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
125*58b9f456SAndroid Build Coastguard Worker try
126*58b9f456SAndroid Build Coastguard Worker #endif
127*58b9f456SAndroid Build Coastguard Worker {
128*58b9f456SAndroid Build Coastguard Worker assert(std::isnan(std::stold(L"NAN", &idx)));
129*58b9f456SAndroid Build Coastguard Worker assert(idx == 3);
130*58b9f456SAndroid Build Coastguard Worker }
131*58b9f456SAndroid Build Coastguard Worker #ifndef TEST_HAS_NO_EXCEPTIONS
132*58b9f456SAndroid Build Coastguard Worker catch (const std::out_of_range&)
133*58b9f456SAndroid Build Coastguard Worker {
134*58b9f456SAndroid Build Coastguard Worker assert(false);
135*58b9f456SAndroid Build Coastguard Worker }
136*58b9f456SAndroid Build Coastguard Worker idx = 0;
137*58b9f456SAndroid Build Coastguard Worker try
138*58b9f456SAndroid Build Coastguard Worker {
139*58b9f456SAndroid Build Coastguard Worker std::stold("", &idx);
140*58b9f456SAndroid Build Coastguard Worker assert(false);
141*58b9f456SAndroid Build Coastguard Worker }
142*58b9f456SAndroid Build Coastguard Worker catch (const std::invalid_argument&)
143*58b9f456SAndroid Build Coastguard Worker {
144*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
145*58b9f456SAndroid Build Coastguard Worker }
146*58b9f456SAndroid Build Coastguard Worker try
147*58b9f456SAndroid Build Coastguard Worker {
148*58b9f456SAndroid Build Coastguard Worker std::stold(L"", &idx);
149*58b9f456SAndroid Build Coastguard Worker assert(false);
150*58b9f456SAndroid Build Coastguard Worker }
151*58b9f456SAndroid Build Coastguard Worker catch (const std::invalid_argument&)
152*58b9f456SAndroid Build Coastguard Worker {
153*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
154*58b9f456SAndroid Build Coastguard Worker }
155*58b9f456SAndroid Build Coastguard Worker try
156*58b9f456SAndroid Build Coastguard Worker {
157*58b9f456SAndroid Build Coastguard Worker std::stold(" - 8", &idx);
158*58b9f456SAndroid Build Coastguard Worker assert(false);
159*58b9f456SAndroid Build Coastguard Worker }
160*58b9f456SAndroid Build Coastguard Worker catch (const std::invalid_argument&)
161*58b9f456SAndroid Build Coastguard Worker {
162*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
163*58b9f456SAndroid Build Coastguard Worker }
164*58b9f456SAndroid Build Coastguard Worker try
165*58b9f456SAndroid Build Coastguard Worker {
166*58b9f456SAndroid Build Coastguard Worker std::stold(L" - 8", &idx);
167*58b9f456SAndroid Build Coastguard Worker assert(false);
168*58b9f456SAndroid Build Coastguard Worker }
169*58b9f456SAndroid Build Coastguard Worker catch (const std::invalid_argument&)
170*58b9f456SAndroid Build Coastguard Worker {
171*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
172*58b9f456SAndroid Build Coastguard Worker }
173*58b9f456SAndroid Build Coastguard Worker try
174*58b9f456SAndroid Build Coastguard Worker {
175*58b9f456SAndroid Build Coastguard Worker std::stold("a1", &idx);
176*58b9f456SAndroid Build Coastguard Worker assert(false);
177*58b9f456SAndroid Build Coastguard Worker }
178*58b9f456SAndroid Build Coastguard Worker catch (const std::invalid_argument&)
179*58b9f456SAndroid Build Coastguard Worker {
180*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
181*58b9f456SAndroid Build Coastguard Worker }
182*58b9f456SAndroid Build Coastguard Worker try
183*58b9f456SAndroid Build Coastguard Worker {
184*58b9f456SAndroid Build Coastguard Worker std::stold(L"a1", &idx);
185*58b9f456SAndroid Build Coastguard Worker assert(false);
186*58b9f456SAndroid Build Coastguard Worker }
187*58b9f456SAndroid Build Coastguard Worker catch (const std::invalid_argument&)
188*58b9f456SAndroid Build Coastguard Worker {
189*58b9f456SAndroid Build Coastguard Worker assert(idx == 0);
190*58b9f456SAndroid Build Coastguard Worker }
191*58b9f456SAndroid Build Coastguard Worker #endif
192*58b9f456SAndroid Build Coastguard Worker }
193