1--TEST--
2Test number_format function : 64bit long tests
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6?>
7--FILE--
8<?php
9
10define("MAX_64Bit", 9223372036854775807);
11define("MAX_32Bit", 2147483647);
12define("MIN_64Bit", -9223372036854775807 - 1);
13define("MIN_32Bit", -2147483647 - 1);
14
15$numbers = array(
16    MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit,
17    MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1,
18    MAX_64Bit - 1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1,
19    // floats rounded as int
20    MAX_64Bit - 1024.0, MIN_64Bit + 1024.0
21);
22
23$precisions = array(
24    5,
25    0,
26    -1,
27    -5,
28    -10,
29    -11,
30    -17,
31    -19,
32    -20,
33    PHP_INT_MIN,
34);
35
36foreach ($numbers as $number) {
37    echo "--- testing: ";
38    var_dump($number);
39    foreach ($precisions as $precision) {
40        echo "... with precision " . $precision . ": ";
41        var_dump(number_format($number, $precision));
42    }
43}
44
45?>
46--EXPECT--
47--- testing: int(9223372036854775807)
48... with precision 5: string(31) "9,223,372,036,854,775,807.00000"
49... with precision 0: string(25) "9,223,372,036,854,775,807"
50... with precision -1: string(25) "9,223,372,036,854,775,810"
51... with precision -5: string(25) "9,223,372,036,854,800,000"
52... with precision -10: string(25) "9,223,372,040,000,000,000"
53... with precision -11: string(25) "9,223,372,000,000,000,000"
54... with precision -17: string(25) "9,200,000,000,000,000,000"
55... with precision -19: string(26) "10,000,000,000,000,000,000"
56... with precision -20: string(1) "0"
57... with precision -9223372036854775808: string(1) "0"
58--- testing: int(-9223372036854775808)
59... with precision 5: string(32) "-9,223,372,036,854,775,808.00000"
60... with precision 0: string(26) "-9,223,372,036,854,775,808"
61... with precision -1: string(26) "-9,223,372,036,854,775,810"
62... with precision -5: string(26) "-9,223,372,036,854,800,000"
63... with precision -10: string(26) "-9,223,372,040,000,000,000"
64... with precision -11: string(26) "-9,223,372,000,000,000,000"
65... with precision -17: string(26) "-9,200,000,000,000,000,000"
66... with precision -19: string(27) "-10,000,000,000,000,000,000"
67... with precision -20: string(1) "0"
68... with precision -9223372036854775808: string(1) "0"
69--- testing: int(2147483647)
70... with precision 5: string(19) "2,147,483,647.00000"
71... with precision 0: string(13) "2,147,483,647"
72... with precision -1: string(13) "2,147,483,650"
73... with precision -5: string(13) "2,147,500,000"
74... with precision -10: string(1) "0"
75... with precision -11: string(1) "0"
76... with precision -17: string(1) "0"
77... with precision -19: string(1) "0"
78... with precision -20: string(1) "0"
79... with precision -9223372036854775808: string(1) "0"
80--- testing: int(-2147483648)
81... with precision 5: string(20) "-2,147,483,648.00000"
82... with precision 0: string(14) "-2,147,483,648"
83... with precision -1: string(14) "-2,147,483,650"
84... with precision -5: string(14) "-2,147,500,000"
85... with precision -10: string(1) "0"
86... with precision -11: string(1) "0"
87... with precision -17: string(1) "0"
88... with precision -19: string(1) "0"
89... with precision -20: string(1) "0"
90... with precision -9223372036854775808: string(1) "0"
91--- testing: int(9223372034707292160)
92... with precision 5: string(31) "9,223,372,034,707,292,160.00000"
93... with precision 0: string(25) "9,223,372,034,707,292,160"
94... with precision -1: string(25) "9,223,372,034,707,292,160"
95... with precision -5: string(25) "9,223,372,034,707,300,000"
96... with precision -10: string(25) "9,223,372,030,000,000,000"
97... with precision -11: string(25) "9,223,372,000,000,000,000"
98... with precision -17: string(25) "9,200,000,000,000,000,000"
99... with precision -19: string(26) "10,000,000,000,000,000,000"
100... with precision -20: string(1) "0"
101... with precision -9223372036854775808: string(1) "0"
102--- testing: int(-9223372034707292160)
103... with precision 5: string(32) "-9,223,372,034,707,292,160.00000"
104... with precision 0: string(26) "-9,223,372,034,707,292,160"
105... with precision -1: string(26) "-9,223,372,034,707,292,160"
106... with precision -5: string(26) "-9,223,372,034,707,300,000"
107... with precision -10: string(26) "-9,223,372,030,000,000,000"
108... with precision -11: string(26) "-9,223,372,000,000,000,000"
109... with precision -17: string(26) "-9,200,000,000,000,000,000"
110... with precision -19: string(27) "-10,000,000,000,000,000,000"
111... with precision -20: string(1) "0"
112... with precision -9223372036854775808: string(1) "0"
113--- testing: int(2147483648)
114... with precision 5: string(19) "2,147,483,648.00000"
115... with precision 0: string(13) "2,147,483,648"
116... with precision -1: string(13) "2,147,483,650"
117... with precision -5: string(13) "2,147,500,000"
118... with precision -10: string(1) "0"
119... with precision -11: string(1) "0"
120... with precision -17: string(1) "0"
121... with precision -19: string(1) "0"
122... with precision -20: string(1) "0"
123... with precision -9223372036854775808: string(1) "0"
124--- testing: int(-2147483649)
125... with precision 5: string(20) "-2,147,483,649.00000"
126... with precision 0: string(14) "-2,147,483,649"
127... with precision -1: string(14) "-2,147,483,650"
128... with precision -5: string(14) "-2,147,500,000"
129... with precision -10: string(1) "0"
130... with precision -11: string(1) "0"
131... with precision -17: string(1) "0"
132... with precision -19: string(1) "0"
133... with precision -20: string(1) "0"
134... with precision -9223372036854775808: string(1) "0"
135--- testing: int(4294967294)
136... with precision 5: string(19) "4,294,967,294.00000"
137... with precision 0: string(13) "4,294,967,294"
138... with precision -1: string(13) "4,294,967,290"
139... with precision -5: string(13) "4,295,000,000"
140... with precision -10: string(1) "0"
141... with precision -11: string(1) "0"
142... with precision -17: string(1) "0"
143... with precision -19: string(1) "0"
144... with precision -20: string(1) "0"
145... with precision -9223372036854775808: string(1) "0"
146--- testing: int(4294967295)
147... with precision 5: string(19) "4,294,967,295.00000"
148... with precision 0: string(13) "4,294,967,295"
149... with precision -1: string(13) "4,294,967,300"
150... with precision -5: string(13) "4,295,000,000"
151... with precision -10: string(1) "0"
152... with precision -11: string(1) "0"
153... with precision -17: string(1) "0"
154... with precision -19: string(1) "0"
155... with precision -20: string(1) "0"
156... with precision -9223372036854775808: string(1) "0"
157--- testing: int(4294967293)
158... with precision 5: string(19) "4,294,967,293.00000"
159... with precision 0: string(13) "4,294,967,293"
160... with precision -1: string(13) "4,294,967,290"
161... with precision -5: string(13) "4,295,000,000"
162... with precision -10: string(1) "0"
163... with precision -11: string(1) "0"
164... with precision -17: string(1) "0"
165... with precision -19: string(1) "0"
166... with precision -20: string(1) "0"
167... with precision -9223372036854775808: string(1) "0"
168--- testing: int(9223372036854775806)
169... with precision 5: string(31) "9,223,372,036,854,775,806.00000"
170... with precision 0: string(25) "9,223,372,036,854,775,806"
171... with precision -1: string(25) "9,223,372,036,854,775,810"
172... with precision -5: string(25) "9,223,372,036,854,800,000"
173... with precision -10: string(25) "9,223,372,040,000,000,000"
174... with precision -11: string(25) "9,223,372,000,000,000,000"
175... with precision -17: string(25) "9,200,000,000,000,000,000"
176... with precision -19: string(26) "10,000,000,000,000,000,000"
177... with precision -20: string(1) "0"
178... with precision -9223372036854775808: string(1) "0"
179--- testing: float(9.223372036854776E+18)
180... with precision 5: string(31) "9,223,372,036,854,775,808.00000"
181... with precision 0: string(25) "9,223,372,036,854,775,808"
182... with precision -1: string(25) "9,223,372,036,854,775,808"
183... with precision -5: string(25) "9,223,372,036,854,800,384"
184... with precision -10: string(25) "9,223,372,040,000,000,000"
185... with precision -11: string(25) "9,223,372,000,000,000,000"
186... with precision -17: string(25) "9,200,000,000,000,000,000"
187... with precision -19: string(26) "10,000,000,000,000,000,000"
188... with precision -20: string(1) "0"
189... with precision -9223372036854775808: string(1) "0"
190--- testing: int(-9223372036854775807)
191... with precision 5: string(32) "-9,223,372,036,854,775,807.00000"
192... with precision 0: string(26) "-9,223,372,036,854,775,807"
193... with precision -1: string(26) "-9,223,372,036,854,775,810"
194... with precision -5: string(26) "-9,223,372,036,854,800,000"
195... with precision -10: string(26) "-9,223,372,040,000,000,000"
196... with precision -11: string(26) "-9,223,372,000,000,000,000"
197... with precision -17: string(26) "-9,200,000,000,000,000,000"
198... with precision -19: string(27) "-10,000,000,000,000,000,000"
199... with precision -20: string(1) "0"
200... with precision -9223372036854775808: string(1) "0"
201--- testing: float(-9.223372036854776E+18)
202... with precision 5: string(32) "-9,223,372,036,854,775,808.00000"
203... with precision 0: string(26) "-9,223,372,036,854,775,808"
204... with precision -1: string(26) "-9,223,372,036,854,775,810"
205... with precision -5: string(26) "-9,223,372,036,854,800,000"
206... with precision -10: string(26) "-9,223,372,040,000,000,000"
207... with precision -11: string(26) "-9,223,372,000,000,000,000"
208... with precision -17: string(26) "-9,200,000,000,000,000,000"
209... with precision -19: string(27) "-10,000,000,000,000,000,000"
210... with precision -20: string(1) "0"
211... with precision -9223372036854775808: string(1) "0"
212--- testing: float(9.223372036854775E+18)
213... with precision 5: string(31) "9,223,372,036,854,774,784.00000"
214... with precision 0: string(25) "9,223,372,036,854,774,784"
215... with precision -1: string(25) "9,223,372,036,854,774,780"
216... with precision -5: string(25) "9,223,372,036,854,800,000"
217... with precision -10: string(25) "9,223,372,040,000,000,000"
218... with precision -11: string(25) "9,223,372,000,000,000,000"
219... with precision -17: string(25) "9,200,000,000,000,000,000"
220... with precision -19: string(26) "10,000,000,000,000,000,000"
221... with precision -20: string(1) "0"
222... with precision -9223372036854775808: string(1) "0"
223--- testing: float(-9.223372036854775E+18)
224... with precision 5: string(32) "-9,223,372,036,854,774,784.00000"
225... with precision 0: string(26) "-9,223,372,036,854,774,784"
226... with precision -1: string(26) "-9,223,372,036,854,774,780"
227... with precision -5: string(26) "-9,223,372,036,854,800,000"
228... with precision -10: string(26) "-9,223,372,040,000,000,000"
229... with precision -11: string(26) "-9,223,372,000,000,000,000"
230... with precision -17: string(26) "-9,200,000,000,000,000,000"
231... with precision -19: string(27) "-10,000,000,000,000,000,000"
232... with precision -20: string(1) "0"
233... with precision -9223372036854775808: string(1) "0"
234