xref: /PHP-8.3/ext/bcmath/tests/bcadd.phpt (revision ee226128)
1--TEST--
2bcadd() function
3--EXTENSIONS--
4bcmath
5--INI--
6bcmath.scale=0
7--FILE--
8<?php
9require(__DIR__ . "/run_bcmath_tests_function.inc");
10
11$leftSummands = ["15", "-15", "1", "-9", "14.14", "-16.60", "0.15", "-0.01"];
12$rightSummands = array_merge($leftSummands, [
13    "0",
14    "0.00",
15    "-0",
16    "-0.00",
17    "15151324141414.412312232141241",
18    "-132132245132134.1515123765412",
19    "141241241241241248267654747412",
20    "-149143276547656984948124912",
21    "0.1322135476547459213732911312",
22    "-0.123912932193769965476541321",
23]);
24
25run_bcmath_tests($leftSummands, $rightSummands, "+", bcadd(...));
26
27?>
28--EXPECT--
29Number "15" (scale 0)
3015 + 15                             = 30
3115 + -15                            = 0
3215 + 1                              = 16
3315 + -9                             = 6
3415 + 14.14                          = 29
3515 + -16.60                         = -1
3615 + 0.15                           = 15
3715 + -0.01                          = 14
3815 + 0                              = 15
3915 + 0.00                           = 15
4015 + -0                             = 15
4115 + -0.00                          = 15
4215 + 15151324141414.412312232141241 = 15151324141429
4315 + -132132245132134.1515123765412 = -132132245132119
4415 + 141241241241241248267654747412 = 141241241241241248267654747427
4515 + -149143276547656984948124912   = -149143276547656984948124897
4615 + 0.1322135476547459213732911312 = 15
4715 + -0.123912932193769965476541321 = 14
48
49Number "-15" (scale 0)
50-15 + 15                             = 0
51-15 + -15                            = -30
52-15 + 1                              = -14
53-15 + -9                             = -24
54-15 + 14.14                          = 0
55-15 + -16.60                         = -31
56-15 + 0.15                           = -14
57-15 + -0.01                          = -15
58-15 + 0                              = -15
59-15 + 0.00                           = -15
60-15 + -0                             = -15
61-15 + -0.00                          = -15
62-15 + 15151324141414.412312232141241 = 15151324141399
63-15 + -132132245132134.1515123765412 = -132132245132149
64-15 + 141241241241241248267654747412 = 141241241241241248267654747397
65-15 + -149143276547656984948124912   = -149143276547656984948124927
66-15 + 0.1322135476547459213732911312 = -14
67-15 + -0.123912932193769965476541321 = -15
68
69Number "1" (scale 0)
701 + 15                             = 16
711 + -15                            = -14
721 + 1                              = 2
731 + -9                             = -8
741 + 14.14                          = 15
751 + -16.60                         = -15
761 + 0.15                           = 1
771 + -0.01                          = 0
781 + 0                              = 1
791 + 0.00                           = 1
801 + -0                             = 1
811 + -0.00                          = 1
821 + 15151324141414.412312232141241 = 15151324141415
831 + -132132245132134.1515123765412 = -132132245132133
841 + 141241241241241248267654747412 = 141241241241241248267654747413
851 + -149143276547656984948124912   = -149143276547656984948124911
861 + 0.1322135476547459213732911312 = 1
871 + -0.123912932193769965476541321 = 0
88
89Number "-9" (scale 0)
90-9 + 15                             = 6
91-9 + -15                            = -24
92-9 + 1                              = -8
93-9 + -9                             = -18
94-9 + 14.14                          = 5
95-9 + -16.60                         = -25
96-9 + 0.15                           = -8
97-9 + -0.01                          = -9
98-9 + 0                              = -9
99-9 + 0.00                           = -9
100-9 + -0                             = -9
101-9 + -0.00                          = -9
102-9 + 15151324141414.412312232141241 = 15151324141405
103-9 + -132132245132134.1515123765412 = -132132245132143
104-9 + 141241241241241248267654747412 = 141241241241241248267654747403
105-9 + -149143276547656984948124912   = -149143276547656984948124921
106-9 + 0.1322135476547459213732911312 = -8
107-9 + -0.123912932193769965476541321 = -9
108
109Number "14.14" (scale 0)
11014.14 + 15                             = 29
11114.14 + -15                            = 0
11214.14 + 1                              = 15
11314.14 + -9                             = 5
11414.14 + 14.14                          = 28
11514.14 + -16.60                         = -2
11614.14 + 0.15                           = 14
11714.14 + -0.01                          = 14
11814.14 + 0                              = 14
11914.14 + 0.00                           = 14
12014.14 + -0                             = 14
12114.14 + -0.00                          = 14
12214.14 + 15151324141414.412312232141241 = 15151324141428
12314.14 + -132132245132134.1515123765412 = -132132245132120
12414.14 + 141241241241241248267654747412 = 141241241241241248267654747426
12514.14 + -149143276547656984948124912   = -149143276547656984948124897
12614.14 + 0.1322135476547459213732911312 = 14
12714.14 + -0.123912932193769965476541321 = 14
128
129Number "-16.60" (scale 0)
130-16.60 + 15                             = -1
131-16.60 + -15                            = -31
132-16.60 + 1                              = -15
133-16.60 + -9                             = -25
134-16.60 + 14.14                          = -2
135-16.60 + -16.60                         = -33
136-16.60 + 0.15                           = -16
137-16.60 + -0.01                          = -16
138-16.60 + 0                              = -16
139-16.60 + 0.00                           = -16
140-16.60 + -0                             = -16
141-16.60 + -0.00                          = -16
142-16.60 + 15151324141414.412312232141241 = 15151324141397
143-16.60 + -132132245132134.1515123765412 = -132132245132150
144-16.60 + 141241241241241248267654747412 = 141241241241241248267654747395
145-16.60 + -149143276547656984948124912   = -149143276547656984948124928
146-16.60 + 0.1322135476547459213732911312 = -16
147-16.60 + -0.123912932193769965476541321 = -16
148
149Number "0.15" (scale 0)
1500.15 + 15                             = 15
1510.15 + -15                            = -14
1520.15 + 1                              = 1
1530.15 + -9                             = -8
1540.15 + 14.14                          = 14
1550.15 + -16.60                         = -16
1560.15 + 0.15                           = 0
1570.15 + -0.01                          = 0
1580.15 + 0                              = 0
1590.15 + 0.00                           = 0
1600.15 + -0                             = 0
1610.15 + -0.00                          = 0
1620.15 + 15151324141414.412312232141241 = 15151324141414
1630.15 + -132132245132134.1515123765412 = -132132245132134
1640.15 + 141241241241241248267654747412 = 141241241241241248267654747412
1650.15 + -149143276547656984948124912   = -149143276547656984948124911
1660.15 + 0.1322135476547459213732911312 = 0
1670.15 + -0.123912932193769965476541321 = 0
168
169Number "-0.01" (scale 0)
170-0.01 + 15                             = 14
171-0.01 + -15                            = -15
172-0.01 + 1                              = 0
173-0.01 + -9                             = -9
174-0.01 + 14.14                          = 14
175-0.01 + -16.60                         = -16
176-0.01 + 0.15                           = 0
177-0.01 + -0.01                          = 0
178-0.01 + 0                              = 0
179-0.01 + 0.00                           = 0
180-0.01 + -0                             = 0
181-0.01 + -0.00                          = 0
182-0.01 + 15151324141414.412312232141241 = 15151324141414
183-0.01 + -132132245132134.1515123765412 = -132132245132134
184-0.01 + 141241241241241248267654747412 = 141241241241241248267654747411
185-0.01 + -149143276547656984948124912   = -149143276547656984948124912
186-0.01 + 0.1322135476547459213732911312 = 0
187-0.01 + -0.123912932193769965476541321 = 0
188
189Number "15" (scale 10)
19015 + 15                             = 30.0000000000
19115 + -15                            = 0.0000000000
19215 + 1                              = 16.0000000000
19315 + -9                             = 6.0000000000
19415 + 14.14                          = 29.1400000000
19515 + -16.60                         = -1.6000000000
19615 + 0.15                           = 15.1500000000
19715 + -0.01                          = 14.9900000000
19815 + 0                              = 15.0000000000
19915 + 0.00                           = 15.0000000000
20015 + -0                             = 15.0000000000
20115 + -0.00                          = 15.0000000000
20215 + 15151324141414.412312232141241 = 15151324141429.4123122321
20315 + -132132245132134.1515123765412 = -132132245132119.1515123765
20415 + 141241241241241248267654747412 = 141241241241241248267654747427.0000000000
20515 + -149143276547656984948124912   = -149143276547656984948124897.0000000000
20615 + 0.1322135476547459213732911312 = 15.1322135476
20715 + -0.123912932193769965476541321 = 14.8760870678
208
209Number "-15" (scale 10)
210-15 + 15                             = 0.0000000000
211-15 + -15                            = -30.0000000000
212-15 + 1                              = -14.0000000000
213-15 + -9                             = -24.0000000000
214-15 + 14.14                          = -0.8600000000
215-15 + -16.60                         = -31.6000000000
216-15 + 0.15                           = -14.8500000000
217-15 + -0.01                          = -15.0100000000
218-15 + 0                              = -15.0000000000
219-15 + 0.00                           = -15.0000000000
220-15 + -0                             = -15.0000000000
221-15 + -0.00                          = -15.0000000000
222-15 + 15151324141414.412312232141241 = 15151324141399.4123122321
223-15 + -132132245132134.1515123765412 = -132132245132149.1515123765
224-15 + 141241241241241248267654747412 = 141241241241241248267654747397.0000000000
225-15 + -149143276547656984948124912   = -149143276547656984948124927.0000000000
226-15 + 0.1322135476547459213732911312 = -14.8677864523
227-15 + -0.123912932193769965476541321 = -15.1239129321
228
229Number "1" (scale 10)
2301 + 15                             = 16.0000000000
2311 + -15                            = -14.0000000000
2321 + 1                              = 2.0000000000
2331 + -9                             = -8.0000000000
2341 + 14.14                          = 15.1400000000
2351 + -16.60                         = -15.6000000000
2361 + 0.15                           = 1.1500000000
2371 + -0.01                          = 0.9900000000
2381 + 0                              = 1.0000000000
2391 + 0.00                           = 1.0000000000
2401 + -0                             = 1.0000000000
2411 + -0.00                          = 1.0000000000
2421 + 15151324141414.412312232141241 = 15151324141415.4123122321
2431 + -132132245132134.1515123765412 = -132132245132133.1515123765
2441 + 141241241241241248267654747412 = 141241241241241248267654747413.0000000000
2451 + -149143276547656984948124912   = -149143276547656984948124911.0000000000
2461 + 0.1322135476547459213732911312 = 1.1322135476
2471 + -0.123912932193769965476541321 = 0.8760870678
248
249Number "-9" (scale 10)
250-9 + 15                             = 6.0000000000
251-9 + -15                            = -24.0000000000
252-9 + 1                              = -8.0000000000
253-9 + -9                             = -18.0000000000
254-9 + 14.14                          = 5.1400000000
255-9 + -16.60                         = -25.6000000000
256-9 + 0.15                           = -8.8500000000
257-9 + -0.01                          = -9.0100000000
258-9 + 0                              = -9.0000000000
259-9 + 0.00                           = -9.0000000000
260-9 + -0                             = -9.0000000000
261-9 + -0.00                          = -9.0000000000
262-9 + 15151324141414.412312232141241 = 15151324141405.4123122321
263-9 + -132132245132134.1515123765412 = -132132245132143.1515123765
264-9 + 141241241241241248267654747412 = 141241241241241248267654747403.0000000000
265-9 + -149143276547656984948124912   = -149143276547656984948124921.0000000000
266-9 + 0.1322135476547459213732911312 = -8.8677864523
267-9 + -0.123912932193769965476541321 = -9.1239129321
268
269Number "14.14" (scale 10)
27014.14 + 15                             = 29.1400000000
27114.14 + -15                            = -0.8600000000
27214.14 + 1                              = 15.1400000000
27314.14 + -9                             = 5.1400000000
27414.14 + 14.14                          = 28.2800000000
27514.14 + -16.60                         = -2.4600000000
27614.14 + 0.15                           = 14.2900000000
27714.14 + -0.01                          = 14.1300000000
27814.14 + 0                              = 14.1400000000
27914.14 + 0.00                           = 14.1400000000
28014.14 + -0                             = 14.1400000000
28114.14 + -0.00                          = 14.1400000000
28214.14 + 15151324141414.412312232141241 = 15151324141428.5523122321
28314.14 + -132132245132134.1515123765412 = -132132245132120.0115123765
28414.14 + 141241241241241248267654747412 = 141241241241241248267654747426.1400000000
28514.14 + -149143276547656984948124912   = -149143276547656984948124897.8600000000
28614.14 + 0.1322135476547459213732911312 = 14.2722135476
28714.14 + -0.123912932193769965476541321 = 14.0160870678
288
289Number "-16.60" (scale 10)
290-16.60 + 15                             = -1.6000000000
291-16.60 + -15                            = -31.6000000000
292-16.60 + 1                              = -15.6000000000
293-16.60 + -9                             = -25.6000000000
294-16.60 + 14.14                          = -2.4600000000
295-16.60 + -16.60                         = -33.2000000000
296-16.60 + 0.15                           = -16.4500000000
297-16.60 + -0.01                          = -16.6100000000
298-16.60 + 0                              = -16.6000000000
299-16.60 + 0.00                           = -16.6000000000
300-16.60 + -0                             = -16.6000000000
301-16.60 + -0.00                          = -16.6000000000
302-16.60 + 15151324141414.412312232141241 = 15151324141397.8123122321
303-16.60 + -132132245132134.1515123765412 = -132132245132150.7515123765
304-16.60 + 141241241241241248267654747412 = 141241241241241248267654747395.4000000000
305-16.60 + -149143276547656984948124912   = -149143276547656984948124928.6000000000
306-16.60 + 0.1322135476547459213732911312 = -16.4677864523
307-16.60 + -0.123912932193769965476541321 = -16.7239129321
308
309Number "0.15" (scale 10)
3100.15 + 15                             = 15.1500000000
3110.15 + -15                            = -14.8500000000
3120.15 + 1                              = 1.1500000000
3130.15 + -9                             = -8.8500000000
3140.15 + 14.14                          = 14.2900000000
3150.15 + -16.60                         = -16.4500000000
3160.15 + 0.15                           = 0.3000000000
3170.15 + -0.01                          = 0.1400000000
3180.15 + 0                              = 0.1500000000
3190.15 + 0.00                           = 0.1500000000
3200.15 + -0                             = 0.1500000000
3210.15 + -0.00                          = 0.1500000000
3220.15 + 15151324141414.412312232141241 = 15151324141414.5623122321
3230.15 + -132132245132134.1515123765412 = -132132245132134.0015123765
3240.15 + 141241241241241248267654747412 = 141241241241241248267654747412.1500000000
3250.15 + -149143276547656984948124912   = -149143276547656984948124911.8500000000
3260.15 + 0.1322135476547459213732911312 = 0.2822135476
3270.15 + -0.123912932193769965476541321 = 0.0260870678
328
329Number "-0.01" (scale 10)
330-0.01 + 15                             = 14.9900000000
331-0.01 + -15                            = -15.0100000000
332-0.01 + 1                              = 0.9900000000
333-0.01 + -9                             = -9.0100000000
334-0.01 + 14.14                          = 14.1300000000
335-0.01 + -16.60                         = -16.6100000000
336-0.01 + 0.15                           = 0.1400000000
337-0.01 + -0.01                          = -0.0200000000
338-0.01 + 0                              = -0.0100000000
339-0.01 + 0.00                           = -0.0100000000
340-0.01 + -0                             = -0.0100000000
341-0.01 + -0.00                          = -0.0100000000
342-0.01 + 15151324141414.412312232141241 = 15151324141414.4023122321
343-0.01 + -132132245132134.1515123765412 = -132132245132134.1615123765
344-0.01 + 141241241241241248267654747412 = 141241241241241248267654747411.9900000000
345-0.01 + -149143276547656984948124912   = -149143276547656984948124912.0100000000
346-0.01 + 0.1322135476547459213732911312 = 0.1222135476
347-0.01 + -0.123912932193769965476541321 = -0.1339129321
348