1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // string to_string(int val);
12 // string to_string(unsigned val);
13 // string to_string(long val);
14 // string to_string(unsigned long val);
15 // string to_string(long long val);
16 // string to_string(unsigned long long val);
17 // string to_string(float val);
18 // string to_string(double val);
19 // string to_string(long double val);
25 #include "parse_integer.h"
26 #include "test_macros.h"
31 std::string s
= std::to_string(T(0));
32 assert(s
.size() == 1);
33 assert(s
[s
.size()] == 0);
37 std::string s
= std::to_string(T(12345));
38 assert(s
.size() == 5);
39 assert(s
[s
.size()] == 0);
43 std::string s
= std::to_string(T(-12345));
44 assert(s
.size() == 6);
45 assert(s
[s
.size()] == 0);
46 assert(s
== "-12345");
49 std::string s
= std::to_string(std::numeric_limits
<T
>::max());
50 assert(s
.size() == std::numeric_limits
<T
>::digits10
+ 1);
51 T t
= parse_integer
<T
>(s
);
52 assert(t
== std::numeric_limits
<T
>::max());
55 std::string s
= std::to_string(std::numeric_limits
<T
>::min());
56 T t
= parse_integer
<T
>(s
);
57 assert(t
== std::numeric_limits
<T
>::min());
62 void test_unsigned() {
64 std::string s
= std::to_string(T(0));
65 assert(s
.size() == 1);
66 assert(s
[s
.size()] == 0);
70 std::string s
= std::to_string(T(12345));
71 assert(s
.size() == 5);
72 assert(s
[s
.size()] == 0);
76 std::string s
= std::to_string(std::numeric_limits
<T
>::max());
77 assert(s
.size() == std::numeric_limits
<T
>::digits10
+ 1);
78 T t
= parse_integer
<T
>(s
);
79 assert(t
== std::numeric_limits
<T
>::max());
86 std::string s
= std::to_string(T(0));
87 assert(s
.size() == 8);
88 assert(s
[s
.size()] == 0);
89 assert(s
== "0.000000");
92 std::string s
= std::to_string(T(12345));
93 assert(s
.size() == 12);
94 assert(s
[s
.size()] == 0);
95 assert(s
== "12345.000000");
98 std::string s
= std::to_string(T(-12345));
99 assert(s
.size() == 13);
100 assert(s
[s
.size()] == 0);
101 assert(s
== "-12345.000000");
105 int main(int, char**) {
108 test_signed
<long long>();
109 test_unsigned
<unsigned>();
110 test_unsigned
<unsigned long>();
111 test_unsigned
<unsigned long long>();
113 test_float
<double>();
114 test_float
<long double>();