Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ext/standard/JitRound.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPCompiler\JIT\Context;
use PHPCompiler\JIT\InternalStrictArg as JitInternalStrictArg;
use PHPCompiler\JIT\JitRoundModeArg;
use PHPCompiler\JIT\NamedOptionalCallArgs;
use PHPCompiler\JIT\Variable as JITVariable;
use PHPLLVM\Value;

Expand All @@ -24,10 +25,10 @@ public static function round(Context $context, JITVariable ...$args): Value
}

$number = self::coerceDouble($context, $args[0]);
$precision = $argc >= 2
$precision = isset($args[1]) && !NamedOptionalCallArgs::isOmittedOptional($args[1])
? self::lowerPrecisionArg($context, $args[1])
: $context->getTypeFromString('int64')->constInt(0, false);
$mode = 3 === $argc
$mode = isset($args[2]) && !NamedOptionalCallArgs::isOmittedOptional($args[2])
? JitRoundModeArg::lower($context, $args[2], 'round')
: $context->getTypeFromString('int64')->constInt(StdlibConstants::PHP_ROUND_HALF_UP, false);

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/round.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public function execute(Frame $frame): void
}

$precision = 0;
if ($argc >= 2) {
if (isset($frame->calledArgs[1])) {
$precision = self::vmPrecisionArg($frame);
}

$mode = StdlibConstants::PHP_ROUND_HALF_UP;
if (3 === $argc) {
if (isset($frame->calledArgs[2])) {
$mode = VmRoundMode::resolveRoundModeArg(
$frame->calledArgs[2]->resolveIndirect(),
'round'
Expand Down
2 changes: 2 additions & 0 deletions test/compliance/cases/stdlib/round_named_params.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ stdlib round() num:/precision:/mode: named parameters (#12103, ext/standard/math
<?php
echo round(num: 2.5), "\n";
echo round(2.5, precision: 0, mode: PHP_ROUND_HALF_ODD), "\n";
echo round(2.5, mode: PHP_ROUND_HALF_UP), "\n";
echo round(2.5), "\n";
--EXPECT--
3
3
3
3
8 changes: 8 additions & 0 deletions test/repro/maintainer_gap_round_php_round_half.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

echo round(2.5, 0, PHP_ROUND_HALF_UP), "\n";
echo round(2.5, 0, PHP_ROUND_HALF_DOWN), "\n";
echo round(3.5, 0, PHP_ROUND_HALF_EVEN), "\n";
echo round(2.5, mode: PHP_ROUND_HALF_UP), "\n";