1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/bcmath/tests/number/operators/sub_int.phpt
Saki Takamachi fad899e566 [RFC] Support object types in BCMath (#13741)
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>
2024-09-04 11:12:51 +09:00

60 lines
909 B
PHP

--TEST--
BcMath\Number sub int by operator
--EXTENSIONS--
bcmath
--FILE--
<?php
$values = [
100,
'20',
];
foreach ($values as $value1) {
$num1 = new BcMath\Number($value1);
foreach ($values as $value2) {
echo "{$value1} - {$value2}\n";
$ret = $num1 - ((int) $value2);
$ret2 = ((int) $value1) - (new BcMath\Number($value2));
if ($ret->compare($ret2) !== 0) {
echo "Result is incorrect.\n";
}
var_dump($ret);
echo "\n";
}
}
?>
--EXPECT--
100 - 100
object(BcMath\Number)#2 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
100 - 20
object(BcMath\Number)#3 (2) {
["value"]=>
string(2) "80"
["scale"]=>
int(0)
}
20 - 100
object(BcMath\Number)#1 (2) {
["value"]=>
string(3) "-80"
["scale"]=>
int(0)
}
20 - 20
object(BcMath\Number)#5 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}