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
3 changes: 0 additions & 3 deletions ext/standard/VmMath.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,6 @@ public static function atan2(float $y, float $x): float
*/
public static function nextafter(float $num, float $next): float
{
if (\function_exists('nextafter')) {
return \nextafter($num, $next);
}
if (\is_nan($num)) {
return $num;
}
Expand Down
6 changes: 6 additions & 0 deletions ext/standard/VmVarExportFloat.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public static function format(float $f): string
return $m[1].'.0E'.$m[2];
}

// php-src zend_print_flat_zval: prefer host var_export when dtoa picks a different round-trip (#15584).
$zend = \var_export($f, true);
if ($f === (float) $zend && $zend !== $s) {
return $zend;
}

return $s;
}
}
8 changes: 6 additions & 2 deletions lib/CompilerVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,14 @@ public static function supportsFpow(): bool
return version_compare(self::VERSION, '8.4.0', '>=');
}

/** PHP 8.4+ nextafter() IEEE next representable float (ext/standard/math.c; #9241). */
/**
* PHP 8.4+ nextafter() IEEE next representable float (ext/standard/math.c; #9241, #15584).
*
* Forward profile on 8.4.0-dev — {@see advertisesBuiltinSince} treats -dev as 8.4.0 (#13284).
*/
public static function supportsNextafter(): bool
{
return version_compare(self::VERSION, '8.4.0', '>=');
return self::advertisesBuiltinSince('8.4.0');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/JIT/InternalStrictArg.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public static function requireFloat(
if (!$context->callerStrictTypes) {
return;
}
if (JITVariable::TYPE_NATIVE_LONG === $arg->type || JITVariable::TYPE_NATIVE_DOUBLE === $arg->type) {
if (Variable::TYPE_NATIVE_LONG === $arg->type || Variable::TYPE_NATIVE_DOUBLE === $arg->type) {
return;
}
if (JITVariable::TYPE_VALUE === $arg->type) {
if (Variable::TYPE_VALUE === $arg->type) {
self::enforceFloatValueBox($context, $arg, $function, $paramName, $argNumber);

return;
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/aot/compile-only/nextafter_forward_profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

if (!function_exists('nextafter')) {
fwrite(STDERR, "fail: nextafter not registered\n");
exit(1);
}

echo nextafter(1.0, 2.0) > 1.0 ? "ok\n" : "fail\n";
16 changes: 16 additions & 0 deletions test/repro/maintainer_gap_nextafter_forward_profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

if (!function_exists('nextafter')) {
fwrite(STDERR, "fail: function_exists('nextafter') false on 8.4.0-dev profile\n");
exit(1);
}

$result = nextafter(1.0, 2.0);
if (!is_float($result) || $result <= 1.0) {
fwrite(STDERR, 'fail: nextafter(1.0, 2.0) expected float > 1.0, got '.var_export($result, true)."\n");
exit(1);
}

echo "ok\n";
10 changes: 8 additions & 2 deletions test/unit/CompilerVersionBuiltinAdvertisementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ public function testFpowWithheldOnReferenceProfileUntilStable84(): void
$this->assertFalse(CompilerVersion::supportsFpow());
}

public function testNextafterWithheldOnReferenceProfileUntilStable84(): void
public function testNextafterAdvertisedOnForwardProfile(): void
{
$this->assertFalse(CompilerVersion::supportsNextafter());
$this->assertTrue(CompilerVersion::supportsNextafter());
}

public function testVmRegistersNextafterOnForwardProfile(): void
{
$runtime = new Runtime();
$this->assertTrue(isset($runtime->vmContext->functions['nextafter']));
}

public function testRoundingModeEnumWithheldOnReferenceProfileUntilStable84(): void
Expand Down
10 changes: 8 additions & 2 deletions test/unit/CompilerVersionGateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function testSupportsFpowFalseOnReferenceProfile(): void
$this->assertFalse(CompilerVersion::supportsFpow());
}

public function testSupportsNextafterFalseOnReferenceProfile(): void
public function testSupportsNextafterTrueOnForwardProfile(): void
{
$this->assertFalse(CompilerVersion::supportsNextafter());
$this->assertTrue(CompilerVersion::supportsNextafter());
}

public function testSupportsRoundingModeEnumFalseOnReferenceProfile(): void
Expand Down Expand Up @@ -237,6 +237,12 @@ public function testVmDoesNotRegisterRoundingModeOnReferenceProfile(): void
$this->assertFalse(isset($runtime->vmContext->classes['roundingmode']));
}

public function testVmRegistersNextafterOnForwardProfile(): void
{
$runtime = new Runtime();
$this->assertTrue(isset($runtime->vmContext->functions['nextafter']));
}

public function testVmDoesNotRegisterFpowOnReferenceProfile(): void
{
$runtime = new Runtime();
Expand Down