1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7
11 // XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8
15 // float stof(const string& str, size_t *idx = 0);
16 // float stof(const wstring& str, size_t *idx = 0);
22 #include "test_macros.h"
26 assert(std::stof("0") == 0);
27 assert(std::stof(L"0") == 0);
28 assert(std::stof("-0") == 0);
29 assert(std::stof(L"-0") == 0);
30 assert(std::stof("-10") == -10);
31 assert(std::stof(L"-10.5") == -10.5);
32 assert(std::stof(" 10") == 10);
33 assert(std::stof(L" 10") == 10);
35 assert(std::stof("10g", &idx) == 10);
38 assert(std::stof(L"10g", &idx) == 10);
40 #ifndef TEST_HAS_NO_EXCEPTIONS
44 assert(std::stof("1.e60", &idx) == INFINITY);
47 catch (const std::out_of_range&)
53 assert(std::stof(L"1.e60", &idx) == INFINITY);
56 catch (const std::out_of_range&)
63 assert(std::stof("1.e360", &idx) == INFINITY);
66 catch (const std::out_of_range&)
72 assert(std::stof(L"1.e360", &idx) == INFINITY);
75 catch (const std::out_of_range&)
82 assert(std::stof("INF", &idx) == INFINITY);
85 #ifndef TEST_HAS_NO_EXCEPTIONS
86 catch (const std::out_of_range&)
92 #ifndef TEST_HAS_NO_EXCEPTIONS
96 assert(std::stof(L"INF", &idx) == INFINITY);
99 #ifndef TEST_HAS_NO_EXCEPTIONS
100 catch (const std::out_of_range&)
106 #ifndef TEST_HAS_NO_EXCEPTIONS
110 assert(std::isnan(std::stof("NAN", &idx)));
113 #ifndef TEST_HAS_NO_EXCEPTIONS
114 catch (const std::out_of_range&)
120 #ifndef TEST_HAS_NO_EXCEPTIONS
124 assert(std::isnan(std::stof(L"NAN", &idx)));
127 #ifndef TEST_HAS_NO_EXCEPTIONS
128 catch (const std::out_of_range&)
138 catch (const std::invalid_argument&)
144 std::stof(L"", &idx);
147 catch (const std::invalid_argument&)
153 std::stof(" - 8", &idx);
156 catch (const std::invalid_argument&)
162 std::stof(L" - 8", &idx);
165 catch (const std::invalid_argument&)
171 std::stof("a1", &idx);
174 catch (const std::invalid_argument&)
180 std::stof(L"a1", &idx);
183 catch (const std::invalid_argument&)