1
0
mirror of https://github.com/php/php-src.git synced 2026-03-28 18:22:42 +01:00
Files
archived-php-src/ext/standard/tests/math/round_basic.phpt
Nikita Popov b10416a652 Deprecate passing null to non-nullable arg of internal function
This deprecates passing null to non-nullable scale arguments of
internal functions, with the eventual goal of making the behavior
consistent with userland functions, where null is never accepted
for non-nullable arguments.

This change is expected to cause quite a lot of fallout. In most
cases, calling code should be adjusted to avoid passing null. In
some cases, PHP should be adjusted to make some function arguments
nullable. I have already fixed a number of functions before landing
this, but feel free to file a bug if you encounter a function that
doesn't accept null, but probably should. (The rule of thumb for
this to be applicable is that the function must have special behavior
for 0 or "", which is distinct from the natural behavior of the
parameter.)

RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

Closes GH-6475.
2021-02-11 21:46:13 +01:00

150 lines
4.7 KiB
PHP

--TEST--
Test round() - basic function test for round()
--INI--
precision=14
--FILE--
<?php
echo "*** Testing round() : basic functionality ***\n";
$values = array(123456789,
123.456789,
-4.5679123,
1.23E4,
-4.567E3,
0x234567,
067777777,
"1.234567",
"2.3456789e8");
$precision = array(2,
8,
0x3,
04,
3.6,
"2",
"04",
"3.6",
"2.1e1",
true,
false);
for ($i = 0; $i < count($values); $i++) {
echo "round: $values[$i]\n";
for ($j = 0; $j < count($precision); $j++) {
$res = round($values[$i], $precision[$j]);
echo "...with precision $precision[$j]-> ";
var_dump($res);
}
}
?>
--EXPECT--
*** Testing round() : basic functionality ***
round: 123456789
...with precision 2-> float(123456789)
...with precision 8-> float(123456789)
...with precision 3-> float(123456789)
...with precision 4-> float(123456789)
...with precision 3.6-> float(123456789)
...with precision 2-> float(123456789)
...with precision 04-> float(123456789)
...with precision 3.6-> float(123456789)
...with precision 2.1e1-> float(123456789)
...with precision 1-> float(123456789)
...with precision -> float(123456789)
round: 123.456789
...with precision 2-> float(123.46)
...with precision 8-> float(123.456789)
...with precision 3-> float(123.457)
...with precision 4-> float(123.4568)
...with precision 3.6-> float(123.457)
...with precision 2-> float(123.46)
...with precision 04-> float(123.4568)
...with precision 3.6-> float(123.457)
...with precision 2.1e1-> float(123.456789)
...with precision 1-> float(123.5)
...with precision -> float(123)
round: -4.5679123
...with precision 2-> float(-4.57)
...with precision 8-> float(-4.5679123)
...with precision 3-> float(-4.568)
...with precision 4-> float(-4.5679)
...with precision 3.6-> float(-4.568)
...with precision 2-> float(-4.57)
...with precision 04-> float(-4.5679)
...with precision 3.6-> float(-4.568)
...with precision 2.1e1-> float(-4.5679123)
...with precision 1-> float(-4.6)
...with precision -> float(-5)
round: 12300
...with precision 2-> float(12300)
...with precision 8-> float(12300)
...with precision 3-> float(12300)
...with precision 4-> float(12300)
...with precision 3.6-> float(12300)
...with precision 2-> float(12300)
...with precision 04-> float(12300)
...with precision 3.6-> float(12300)
...with precision 2.1e1-> float(12300)
...with precision 1-> float(12300)
...with precision -> float(12300)
round: -4567
...with precision 2-> float(-4567)
...with precision 8-> float(-4567)
...with precision 3-> float(-4567)
...with precision 4-> float(-4567)
...with precision 3.6-> float(-4567)
...with precision 2-> float(-4567)
...with precision 04-> float(-4567)
...with precision 3.6-> float(-4567)
...with precision 2.1e1-> float(-4567)
...with precision 1-> float(-4567)
...with precision -> float(-4567)
round: 2311527
...with precision 2-> float(2311527)
...with precision 8-> float(2311527)
...with precision 3-> float(2311527)
...with precision 4-> float(2311527)
...with precision 3.6-> float(2311527)
...with precision 2-> float(2311527)
...with precision 04-> float(2311527)
...with precision 3.6-> float(2311527)
...with precision 2.1e1-> float(2311527)
...with precision 1-> float(2311527)
...with precision -> float(2311527)
round: 14680063
...with precision 2-> float(14680063)
...with precision 8-> float(14680063)
...with precision 3-> float(14680063)
...with precision 4-> float(14680063)
...with precision 3.6-> float(14680063)
...with precision 2-> float(14680063)
...with precision 04-> float(14680063)
...with precision 3.6-> float(14680063)
...with precision 2.1e1-> float(14680063)
...with precision 1-> float(14680063)
...with precision -> float(14680063)
round: 1.234567
...with precision 2-> float(1.23)
...with precision 8-> float(1.234567)
...with precision 3-> float(1.235)
...with precision 4-> float(1.2346)
...with precision 3.6-> float(1.235)
...with precision 2-> float(1.23)
...with precision 04-> float(1.2346)
...with precision 3.6-> float(1.235)
...with precision 2.1e1-> float(1.234567)
...with precision 1-> float(1.2)
...with precision -> float(1)
round: 2.3456789e8
...with precision 2-> float(234567890)
...with precision 8-> float(234567890)
...with precision 3-> float(234567890)
...with precision 4-> float(234567890)
...with precision 3.6-> float(234567890)
...with precision 2-> float(234567890)
...with precision 04-> float(234567890)
...with precision 3.6-> float(234567890)
...with precision 2.1e1-> float(234567890)
...with precision 1-> float(234567890)
...with precision -> float(234567890)