aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-10-19 00:12:56 +0900
committernsfisis <nsfisis@gmail.com>2025-10-19 00:12:56 +0900
commite0c0a48051530b82c164ea25a806ba8c38eeb3d5 (patch)
treed80fd5b0dd584bd4c117f15c8ae526d8b8fb7898 /src
parent17bb2c1d31deb6799891f79ca317f3f09728bc3e (diff)
downloadphp-next-after-e0c0a48051530b82c164ea25a806ba8c38eeb3d5.tar.gz
php-next-after-e0c0a48051530b82c164ea25a806ba8c38eeb3d5.tar.zst
php-next-after-e0c0a48051530b82c164ea25a806ba8c38eeb3d5.zip
feat: add minValue()
Diffstat (limited to 'src')
-rw-r--r--src/NextAfter.php13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/NextAfter.php b/src/NextAfter.php
index e2b7706..678de25 100644
--- a/src/NextAfter.php
+++ b/src/NextAfter.php
@@ -11,7 +11,6 @@ use function pack;
use function unpack;
use const INF;
use const NAN;
-use const PHP_FLOAT_MIN;
use const PHP_INT_SIZE;
final class NextAfter
@@ -46,7 +45,7 @@ final class NextAfter
return INF;
}
if ($x === 0.0) {
- return PHP_FLOAT_MIN;
+ return self::minValue();
}
$u = self::floatToInt($x);
return $x > 0.0 ? self::intToFloat($u + 1) :
@@ -66,7 +65,7 @@ final class NextAfter
return -INF;
}
if ($x === 0.0) {
- return -PHP_FLOAT_MIN;
+ return -self::minValue();
}
$u = self::floatToInt($x);
return $x > 0.0 ? self::intToFloat($u - 1) :
@@ -77,6 +76,14 @@ final class NextAfter
/**
* @phpstan-pure
*/
+ public static function minValue(): float
+ {
+ return self::intToFloat(1);
+ }
+
+ /**
+ * @phpstan-pure
+ */
private static function intToFloat(int $x): float
{
return self::unpackFloat64(self::packInt64($x));