-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathFloatInfo.php
More file actions
37 lines (32 loc) · 834 Bytes
/
FloatInfo.php
File metadata and controls
37 lines (32 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Structures;
class FloatInfo implements StructureInterface
{
use \PHPJava\Kernel\Core\BinaryReader;
use \PHPJava\Kernel\Core\ConstantPool;
use \PHPJava\Kernel\Core\DebugTool;
/**
* @var int
*/
private $bytes;
/**
* @var int
*/
private $realByte;
public function execute(): void
{
$this->bytes = $this->readUnsignedInt();
}
public function getBytes(): float
{
if ($this->realByte) {
return $this->realByte;
}
$bits = $this->bytes;
$s = ($bits >> 31) == 0 ? 1 : -1;
$e = ($bits >> 23) & 0xff;
$m = ($e == 0) ? (($bits & 0x7fffff) << 1) : ($bits & 0x7fffff) | 0x800000;
return $this->realByte = ($s * $m * pow(2, $e - 150));
}
}