1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Files
archived-php-src/ext/bcmath/tests/number/construct_64bit.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

143 lines
2.0 KiB
PHP

--TEST--
BcMath\Number construct 64 bit
--EXTENSIONS--
bcmath
--SKIPIF--
<?php
if (PHP_INT_MAX <= 2147483647) {
die('skip only 64 bit');
}
?>
--FILE--
<?php
$values = [
'0',
'0.00',
'.1',
'0.1',
'0.20',
'0.00000030',
'1234.0',
'123450',
'',
'-',
'.',
0,
123,
9223372036854775806,
PHP_INT_MAX,
-9223372036854775807,
PHP_INT_MIN,
];
foreach ($values as $value) {
$num = new BcMath\Number($value);
var_dump($num);
unset($num);
}
?>
--EXPECT--
object(BcMath\Number)#1 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(4) "0.00"
["scale"]=>
int(2)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(3) "0.1"
["scale"]=>
int(1)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(3) "0.1"
["scale"]=>
int(1)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(4) "0.20"
["scale"]=>
int(2)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(10) "0.00000030"
["scale"]=>
int(8)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(6) "1234.0"
["scale"]=>
int(1)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(6) "123450"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(3) "123"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(19) "9223372036854775806"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(19) "9223372036854775807"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(20) "-9223372036854775807"
["scale"]=>
int(0)
}
object(BcMath\Number)#1 (2) {
["value"]=>
string(20) "-9223372036854775808"
["scale"]=>
int(0)
}