1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
--TEST--
BcMath\Number compare() with scale
--EXTENSIONS--
bcmath
--FILE--
<?php
$values1 = [
new BcMath\Number('0.001'),
new BcMath\Number('-0.001'),
];
$values2 = [
0,
-0,
'0.0011',
'-0.0011',
];
$value1 = new BcMath\Number('0.001');
$scales = [0, 2, 3, 4];
foreach ($scales as $scale) {
echo "========== scale is {$scale} ==========\n";
foreach ($values1 as $value1) {
foreach ($values2 as $value2) {
$output = str_pad("{$value1} <=> {$value2}: ", 20, ' ', STR_PAD_LEFT);
$output .= str_pad((string) $value1->compare($value2, $scale), 2, ' ', STR_PAD_LEFT);
echo "{$output}\n";
}
}
}
?>
--EXPECT--
========== scale is 0 ==========
0.001 <=> 0: 0
0.001 <=> 0: 0
0.001 <=> 0.0011: 0
0.001 <=> -0.0011: 0
-0.001 <=> 0: 0
-0.001 <=> 0: 0
-0.001 <=> 0.0011: 0
-0.001 <=> -0.0011: 0
========== scale is 2 ==========
0.001 <=> 0: 0
0.001 <=> 0: 0
0.001 <=> 0.0011: 0
0.001 <=> -0.0011: 0
-0.001 <=> 0: 0
-0.001 <=> 0: 0
-0.001 <=> 0.0011: 0
-0.001 <=> -0.0011: 0
========== scale is 3 ==========
0.001 <=> 0: 1
0.001 <=> 0: 1
0.001 <=> 0.0011: 0
0.001 <=> -0.0011: 1
-0.001 <=> 0: -1
-0.001 <=> 0: -1
-0.001 <=> 0.0011: -1
-0.001 <=> -0.0011: 0
========== scale is 4 ==========
0.001 <=> 0: 1
0.001 <=> 0: 1
0.001 <=> 0.0011: -1
0.001 <=> -0.0011: 1
-0.001 <=> 0: -1
-0.001 <=> 0: -1
-0.001 <=> 0.0011: -1
-0.001 <=> -0.0011: 1
|