Skip to content

Commit b18cb17

Browse files
committed
Support double/float calculation.
1 parent 59437bc commit b18cb17

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Sorry, I do not have enough time (T_T)
2323

2424
- Implements
2525
- Event
26-
- double/float calculation.
2726
- Many built-in libraries (ex. java.lang.xxx, java.io.xxx and so on)
2827
- etc...
2928

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "JVM emulator by PHP",
44
"type": "library",
55
"license": "MIT",
6-
"version": "0.0.4.2-dev",
6+
"version": "0.0.4.5-dev",
77
"authors": [
88
{
99
"name": "memory"

src/Kernel/Structures/_Float.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public function execute(): void
1616
}
1717
public function getBytes()
1818
{
19-
return $this->bytes;
19+
return BinaryTool::convertFloatToIEEE754($this->bytes);
2020
}
2121
}

src/Utilities/BinaryTool.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,13 @@ final public static function convertDoubleToIEEE754($doubleValue, $rounded = 8)
205205
(($bits & 0xfffffffffffff) << 1) : ($bits & 0xfffffffffffff) | 0x10000000000000;
206206
return $s * $m * pow(2, $e - 1075);
207207
}
208+
209+
final public static function convertFloatToIEEE754($floatValue, $rounded = 8)
210+
{
211+
$bits = $floatValue;
212+
$s = ($bits >> 31) == 0 ? 1 : -1;
213+
$e = ($bits >> 23) & 0xff;
214+
$m = ($e == 0) ? ($bits & 0x7fffff) << 1 : ($bits & 0x7fffff) | 0x800000;;
215+
return $s * $m * pow(2, $e - 150);
216+
}
208217
}

0 commit comments

Comments
 (0)