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"
33 std::string s
= std::to_string(T(0));
34 assert(s
.size() == 1);
35 assert(s
[s
.size()] == 0);
39 std::string s
= std::to_string(T(12345));
40 assert(s
.size() == 5);
41 assert(s
[s
.size()] == 0);
45 std::string s
= std::to_string(T(-12345));
46 assert(s
.size() == 6);
47 assert(s
[s
.size()] == 0);
48 assert(s
== "-12345");
51 std::string s
= std::to_string(std::numeric_limits
<T
>::max());
52 assert(s
.size() == std::numeric_limits
<T
>::digits10
+ 1);
53 T t
= parse_integer
<T
>(s
);
54 assert(t
== std::numeric_limits
<T
>::max());
57 std::string s
= std::to_string(std::numeric_limits
<T
>::min());
58 T t
= parse_integer
<T
>(s
);
59 assert(t
== std::numeric_limits
<T
>::min());
68 std::string s
= std::to_string(T(0));
69 assert(s
.size() == 1);
70 assert(s
[s
.size()] == 0);
74 std::string s
= std::to_string(T(12345));
75 assert(s
.size() == 5);
76 assert(s
[s
.size()] == 0);
80 std::string s
= std::to_string(std::numeric_limits
<T
>::max());
81 assert(s
.size() == std::numeric_limits
<T
>::digits10
+ 1);
82 T t
= parse_integer
<T
>(s
);
83 assert(t
== std::numeric_limits
<T
>::max());
92 std::string s
= std::to_string(T(0));
93 assert(s
.size() == 8);
94 assert(s
[s
.size()] == 0);
95 assert(s
== "0.000000");
98 std::string s
= std::to_string(T(12345));
99 assert(s
.size() == 12);
100 assert(s
[s
.size()] == 0);
101 assert(s
== "12345.000000");
104 std::string s
= std::to_string(T(-12345));
105 assert(s
.size() == 13);
106 assert(s
[s
.size()] == 0);
107 assert(s
== "-12345.000000");
111 int main(int, char**)
115 test_signed
<long long>();
116 test_unsigned
<unsigned>();
117 test_unsigned
<unsigned long>();
118 test_unsigned
<unsigned long long>();
120 test_float
<double>();
121 test_float
<long double>();