Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Support double/float calculation.
  • Loading branch information
m3m0r7 committed Mar 4, 2019
commit b18cb170b693df15e6e8ad3d20af85094077bcde
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Sorry, I do not have enough time (T_T)

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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "JVM emulator by PHP",
"type": "library",
"license": "MIT",
"version": "0.0.4.2-dev",
"version": "0.0.4.5-dev",
"authors": [
{
"name": "memory"
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Structures/_Float.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public function execute(): void
}
public function getBytes()
{
return $this->bytes;
return BinaryTool::convertFloatToIEEE754($this->bytes);
}
}
9 changes: 9 additions & 0 deletions src/Utilities/BinaryTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,13 @@ final public static function convertDoubleToIEEE754($doubleValue, $rounded = 8)
(($bits & 0xfffffffffffff) << 1) : ($bits & 0xfffffffffffff) | 0x10000000000000;
return $s * $m * pow(2, $e - 1075);
}

final public static function convertFloatToIEEE754($floatValue, $rounded = 8)
{
$bits = $floatValue;
$s = ($bits >> 31) == 0 ? 1 : -1;
$e = ($bits >> 23) & 0xff;
$m = ($e == 0) ? ($bits & 0x7fffff) << 1 : ($bits & 0x7fffff) | 0x800000;;
return $s * $m * pow(2, $e - 150);
}
}