Skip to content

Commit d2260c9

Browse files
committed
Add fadd, fmul and fsub
1 parent f2e9b23 commit d2260c9

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/Kernel/Mnemonics/_fadd.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Float;
6+
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
58

69
final class _fadd implements OperationInterface
710
{
@@ -10,6 +13,16 @@ final class _fadd implements OperationInterface
1013

1114
public function execute(): void
1215
{
13-
throw new NotImplementedException(__CLASS__);
16+
$rightValue = $this->popFromOperandStack();
17+
$leftValue = $this->popFromOperandStack();
18+
19+
$this->pushToOperandStack(
20+
_Float::get(
21+
BinaryTool::add(
22+
Extractor::getRealValue($leftValue),
23+
Extractor::getRealValue($rightValue)
24+
)
25+
)
26+
);
1427
}
1528
}

src/Kernel/Mnemonics/_fmul.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Float;
6+
use PHPJava\Kernel\Types\_Int;
7+
use PHPJava\Utilities\BinaryTool;
8+
use PHPJava\Utilities\Extractor;
59

610
final class _fmul implements OperationInterface
711
{
@@ -10,6 +14,16 @@ final class _fmul implements OperationInterface
1014

1115
public function execute(): void
1216
{
13-
throw new NotImplementedException(__CLASS__);
17+
$value2 = $this->popFromOperandStack();
18+
$value1 = $this->popFromOperandStack();
19+
20+
$this->pushToOperandStack(
21+
_Float::get(
22+
BinaryTool::multiply(
23+
Extractor::getRealValue($value1),
24+
Extractor::getRealValue($value2)
25+
)
26+
)
27+
);
1428
}
1529
}

src/Kernel/Mnemonics/_fsub.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Float;
6+
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
58

69
final class _fsub implements OperationInterface
710
{
@@ -10,6 +13,16 @@ final class _fsub implements OperationInterface
1013

1114
public function execute(): void
1215
{
13-
throw new NotImplementedException(__CLASS__);
16+
$rightValue = $this->popFromOperandStack();
17+
$leftValue = $this->popFromOperandStack();
18+
19+
$this->pushToOperandStack(
20+
_Float::get(
21+
BinaryTool::sub(
22+
Extractor::getRealValue($leftValue),
23+
Extractor::getRealValue($rightValue)
24+
)
25+
)
26+
);
1427
}
1528
}

0 commit comments

Comments
 (0)