aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-04-05 23:26:25 +0900
committernsfisis <nsfisis@gmail.com>2025-04-06 02:03:32 +0900
commit3d0f0b06ee25571034a13a43d2ca660ef687afa9 (patch)
tree9d82454afbd8d26d41180db8718c863f9225e83f /tests/src
parent24d00a02f51138f1191c8b1f72ccdb14fc622b11 (diff)
downloadphp-waddiwasi-3d0f0b06ee25571034a13a43d2ca660ef687afa9.tar.gz
php-waddiwasi-3d0f0b06ee25571034a13a43d2ca660ef687afa9.tar.zst
php-waddiwasi-3d0f0b06ee25571034a13a43d2ca660ef687afa9.zip
fix: pass ConversionsTest, FloatExprsTest, FloatLiteralsTest
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/SpecTestsuites/SpecTestsuiteBase.php14
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
index 6d92ed8..41afbf8 100644
--- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php
+++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
@@ -258,7 +258,7 @@ abstract class SpecTestsuiteBase extends TestCase
'i64' => unpack('q', self::convertInt64ToBinary($value))[1],
'f32' => match ($value) {
'nan:canonical', 'nan:arithmetic' => $value,
- default => unpack('g', pack('V', (int)$value))[1],
+ default => self::i32ToF32((int)$value),
},
'f64' => match ($value) {
'nan:canonical', 'nan:arithmetic' => $value,
@@ -270,6 +270,18 @@ abstract class SpecTestsuiteBase extends TestCase
};
}
+ private static function i32ToF32(int $x): float
+ {
+ if (($x & 0b01111111100000000000000000000000) === 0b01111111100000000000000000000000) {
+ $sign = ($x & 0b10000000000000000000000000000000) === 0 ? 1 : -1;
+ $payload = $x & 0b00000000011111111111111111111111;
+ $i = ($sign === 1 ? 0 : PHP_INT_MIN) | 0b0111111111110000000000000000000000000000000000000000000000000000 | ($payload << (52 - 23));
+ return unpack('e', pack('q', $i))[1];
+ } else {
+ return unpack('g', pack('V', $x))[1];
+ }
+ }
+
private function doAction(
array $action,
): array {