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>
37 lines
755 B
PHP
37 lines
755 B
PHP
--TEST--
|
|
BcMath\Number sqrt() with scale
|
|
--EXTENSIONS--
|
|
bcmath
|
|
--FILE--
|
|
<?php
|
|
|
|
$radicants = [
|
|
"0",
|
|
"0.00",
|
|
"-0",
|
|
"-0.00",
|
|
"15151324141414.412312232141241",
|
|
"141241241241241248267654747412",
|
|
"0.1322135476547459213732911312",
|
|
"14.14",
|
|
"0.15",
|
|
"15",
|
|
"1",
|
|
];
|
|
$scales = [0, 10];
|
|
|
|
foreach ($scales as $scale) {
|
|
foreach ($radicants as $radicant) {
|
|
$func_ret = bcsqrt($radicant, $scale);
|
|
$method_ret = (new BcMath\Number($radicant))->sqrt($scale);
|
|
if ($method_ret->compare($func_ret) !== 0) {
|
|
echo "Result is incorrect.\n";
|
|
var_dump($radicant, $scale, $func_ret, $method_ret, ((string) $method_ret) === $func_ret);
|
|
}
|
|
}
|
|
}
|
|
echo 'done!';
|
|
?>
|
|
--EXPECT--
|
|
done!
|