Skip to content

Commit 2e44b1f

Browse files
committed
Added try-catch to run_bcmath_tests_function.inc
1 parent 4cfc788 commit 2e44b1f

File tree

2 files changed

+19
-42
lines changed

2 files changed

+19
-42
lines changed

ext/bcmath/tests/bcpow.phpt

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,7 @@ bcmath
66
bcmath.scale=0
77
--FILE--
88
<?php
9-
// slightly modified run_bcmath_tests_function.inc for bcpow testing
10-
const STRING_PADDING = 30;
11-
function run_bcmath_tests(
12-
$firstTerms,
13-
$secondTerms,
14-
$symbol,
15-
$bcmath_function
16-
) {
17-
$scales = [0, 10];
18-
foreach ($scales as $scale) {
19-
foreach ($firstTerms as $firstTerm) {
20-
echo "Number \"$firstTerm\" (scale $scale)\n";
21-
foreach ($secondTerms as $secondTerm) {
22-
if (in_array($firstTerm, ['0', '-0'], true) && $secondTerm[0] === '-') {
23-
$ret = 'skip negative power of zero';
24-
} else {
25-
$ret = $bcmath_function($firstTerm, $secondTerm, $scale);
26-
}
27-
echo $firstTerm,
28-
" $symbol ",
29-
str_pad($secondTerm, STRING_PADDING),
30-
" = ",
31-
$ret,
32-
"\n";
33-
}
34-
echo "\n";
35-
}
36-
}
37-
}
9+
require(__DIR__ . "/run_bcmath_tests_function.inc");
3810

3911
$exponents = ["15", "-15", "1", "-9", "0", "-0"];
4012
$baseNumbers = array_merge($exponents, [
@@ -88,19 +60,19 @@ Number "-9" (scale 0)
8860

8961
Number "0" (scale 0)
9062
0 ** 15 = 0
91-
0 ** -15 = skip negative power of zero
63+
0 ** -15 = Negative power of zero
9264
0 ** 1 = 0
93-
0 ** -9 = skip negative power of zero
65+
0 ** -9 = Negative power of zero
9466
0 ** 0 = 1
95-
0 ** -0 = skip negative power of zero
67+
0 ** -0 = 1
9668

9769
Number "-0" (scale 0)
9870
-0 ** 15 = 0
99-
-0 ** -15 = skip negative power of zero
71+
-0 ** -15 = Negative power of zero
10072
-0 ** 1 = 0
101-
-0 ** -9 = skip negative power of zero
73+
-0 ** -9 = Negative power of zero
10274
-0 ** 0 = 1
103-
-0 ** -0 = skip negative power of zero
75+
-0 ** -0 = 1
10476

10577
Number "14.14" (scale 0)
10678
14.14 ** 15 = 180609729388653367
@@ -216,19 +188,19 @@ Number "-9" (scale 10)
216188

217189
Number "0" (scale 10)
218190
0 ** 15 = 0.0000000000
219-
0 ** -15 = skip negative power of zero
191+
0 ** -15 = Negative power of zero
220192
0 ** 1 = 0.0000000000
221-
0 ** -9 = skip negative power of zero
193+
0 ** -9 = Negative power of zero
222194
0 ** 0 = 1.0000000000
223-
0 ** -0 = skip negative power of zero
195+
0 ** -0 = 1.0000000000
224196

225197
Number "-0" (scale 10)
226198
-0 ** 15 = 0.0000000000
227-
-0 ** -15 = skip negative power of zero
199+
-0 ** -15 = Negative power of zero
228200
-0 ** 1 = 0.0000000000
229-
-0 ** -9 = skip negative power of zero
201+
-0 ** -9 = Negative power of zero
230202
-0 ** 0 = 1.0000000000
231-
-0 ** -0 = skip negative power of zero
203+
-0 ** -0 = 1.0000000000
232204

233205
Number "14.14" (scale 10)
234206
14.14 ** 15 = 180609729388653367.2586094856

ext/bcmath/tests/run_bcmath_tests_function.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ function run_bcmath_tests(
1313
foreach ($firstTerms as $firstTerm) {
1414
echo "Number \"$firstTerm\" (scale $scale)\n";
1515
foreach ($secondTerms as $secondTerm) {
16+
try {
17+
$ret = $bcmath_function($firstTerm, $secondTerm, $scale);
18+
} catch (Throwable $e) {
19+
$ret = $e->getMessage();
20+
}
1621
echo $firstTerm,
1722
" $symbol ",
1823
str_pad($secondTerm, STRING_PADDING),
1924
" = ",
20-
$bcmath_function($firstTerm, $secondTerm, $scale),
25+
$ret,
2126
"\n";
2227
}
2328
echo "\n";

0 commit comments

Comments
 (0)