aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-05-07 21:21:53 +0900
committernsfisis <nsfisis@gmail.com>2024-05-07 21:21:53 +0900
commit579b41ce7bbf6d24b300d0f0736701ef63ae58f7 (patch)
treee2facbc0127c6d80b4dde4cb39348a00ed6f77e9
parentf768af46ab92596a7df60658dd684c751f3c78d1 (diff)
downloadphp-waddiwasi-579b41ce7bbf6d24b300d0f0736701ef63ae58f7.tar.gz
php-waddiwasi-579b41ce7bbf6d24b300d0f0736701ef63ae58f7.tar.zst
php-waddiwasi-579b41ce7bbf6d24b300d0f0736701ef63ae58f7.zip
test: ConstTest passed
-rw-r--r--tests/src/SpecTestsuites/SpecTestsuiteBase.php13
1 files changed, 11 insertions, 2 deletions
diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
index 05b7846..9939196 100644
--- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php
+++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
@@ -210,7 +210,7 @@ abstract class SpecTestsuiteBase extends TestCase
"result $i mismatch" . $message,
);
} elseif ($expectedResult['type'] === 'i64') {
- $expectedValue = unpack('q', pack('q', (int)$expectedResult['value']))[1];
+ $expectedValue = unpack('q', self::convertInt64ToBinary($expectedResult['value']))[1];
$this->assertSame(
$expectedValue,
$actualResult,
@@ -232,7 +232,7 @@ abstract class SpecTestsuiteBase extends TestCase
);
}
} elseif ($expectedResult['type'] === 'f64') {
- $expectedValue = unpack('e', pack('q', (int)$expectedResult['value']))[1];
+ $expectedValue = unpack('e', self::convertInt64ToBinary($expectedResult['value']))[1];
if (is_nan($expectedValue)) {
// @todo check NaN bit pattern.
$this->assertTrue(
@@ -286,4 +286,13 @@ abstract class SpecTestsuiteBase extends TestCase
'trap kind mismatch' . $message,
);
}
+
+ static private function convertInt64ToBinary(string $value): string
+ {
+ // 2^63-1 < $value
+ if (bccomp(bcsub(bcpow('2', '63'), '1'), $value) < 0) {
+ $value = bcsub($value, bcpow('2', '64'));
+ }
+ return pack('q', (int)$value);
+ }
}