mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Added BcMath\Number class. It is an immutable object, has methods that are equivalent to existing BCMath calculation functions, and can also be calculated using operators. The existing BCMath function returned a string for each calculation, but this class returns an object. RFC: https://wiki.php.net/rfc/support_object_type_in_bcmath, https://wiki.php.net/rfc/fix_up_bcmath_number_class --------- Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
40 lines
899 B
PHP
40 lines
899 B
PHP
--TEST--
|
|
BcMath\Number div() with scale
|
|
--EXTENSIONS--
|
|
bcmath
|
|
--FILE--
|
|
<?php
|
|
|
|
$scales = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
|
|
$values1 = ['100.012', '-100.012'];
|
|
|
|
$values2 = [
|
|
[100, 'int'],
|
|
[-30, 'int'],
|
|
['-20', 'string'],
|
|
['0.01', 'string'],
|
|
['-0.40', 'string'],
|
|
[new BcMath\Number('80.3'), 'object'],
|
|
[new BcMath\Number('-50.6'), 'object'],
|
|
];
|
|
|
|
foreach ($scales as $scale) {
|
|
foreach ($values1 as $value1) {
|
|
$num = new BcMath\Number($value1);
|
|
|
|
foreach ($values2 as [$value2, $type]) {
|
|
$func_ret = bcdiv($value1, (string) $value2, $scale);
|
|
$method_ret = $num->div($value2, $scale);
|
|
if ($method_ret->compare($func_ret) !== 0) {
|
|
echo "Result is incorrect.\n";
|
|
var_dump($value1, $value2, $scale, $func_ret, $method_ret);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
echo 'done!';
|
|
?>
|
|
--EXPECT--
|
|
done!
|