mirror of
https://github.com/php/php-src.git
synced 2026-04-28 02:33:17 +02:00
fad899e566
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>
38 lines
737 B
PHP
38 lines
737 B
PHP
--TEST--
|
|
BcMath\Number floor()
|
|
--EXTENSIONS--
|
|
bcmath
|
|
--FILE--
|
|
<?php
|
|
$nums = [
|
|
'0',
|
|
'0.00',
|
|
'-0',
|
|
'-0.00',
|
|
'0.01',
|
|
'0.000000000000000000000000000000000000000001',
|
|
'-0.01',
|
|
'-0.000000000000000000000000000000000000000001',
|
|
'1',
|
|
'1.0000',
|
|
'1.0001',
|
|
'100000.000000000000000000000000000000000000000001',
|
|
'-1',
|
|
'-1.0000',
|
|
'-1.0001',
|
|
'-100000.000000000000000000000000000000000000000001',
|
|
];
|
|
|
|
foreach ($nums as $num) {
|
|
$func_ret = bcfloor($num);
|
|
$method_ret = (new BcMath\Number($num))->floor();
|
|
if ($method_ret->compare($func_ret) !== 0) {
|
|
echo "Result is incorrect.\n";
|
|
var_dump($num, $func_ret, $method_ret);
|
|
}
|
|
}
|
|
echo 'done!';
|
|
?>
|
|
--EXPECT--
|
|
done!
|