-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathDoubleInfo.php
More file actions
43 lines (37 loc) · 1005 Bytes
/
DoubleInfo.php
File metadata and controls
43 lines (37 loc) · 1005 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
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Structures;
class DoubleInfo implements StructureInterface
{
use \PHPJava\Kernel\Core\BinaryReader;
use \PHPJava\Kernel\Core\ConstantPool;
use \PHPJava\Kernel\Core\DebugTool;
/**
* @var int
*/
private $highBytes;
/**
* @var int
*/
private $lowBytes;
/**
* @var int
*/
private $realByte;
public function execute(): void
{
$this->highBytes = $this->readUnsignedInt();
$this->lowBytes = $this->readUnsignedInt();
}
public function getBytes(): float
{
if ($this->realByte) {
return $this->realByte;
}
$bits = ($this->highBytes << 32) + $this->lowBytes;
$s = ($bits >> 63) == 0 ? 1 : -1;
$e = ($bits >> 52) & 0x7ff;
$m = ($e == 0) ? (($bits & 0xfffffffffffff) << 1) : ($bits & 0xfffffffffffff) | 0x10000000000000;
return $this->realByte = ($s * $m * pow(2, $e - 1075));
}
}