Skip to content

Commit 79bcae7

Browse files
committed
Add lcmp operation
1 parent 8366cb8 commit 79bcae7

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/Kernel/Mnemonics/_lcmp.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22
namespace PHPJava\Kernel\Mnemonics;
33

4-
use PHPJava\Exceptions\NotImplementedException;
4+
use Brick\Math\BigInteger;
5+
use PHPJava\Kernel\Types\_Int;
56

67
final class _lcmp implements OperationInterface
78
{
@@ -10,6 +11,21 @@ final class _lcmp implements OperationInterface
1011

1112
public function execute(): void
1213
{
13-
throw new NotImplementedException(__CLASS__);
14+
$value2 = $this->popFromOperandStack();
15+
$value1 = $this->popFromOperandStack();
16+
17+
$compare = BigInteger::of($value1)->compareTo($value2);
18+
19+
if ($compare == 1) {
20+
$this->pushToOperandStack(_Int::get(1));
21+
return;
22+
}
23+
24+
if ($compare == -1) {
25+
$this->pushToOperandStack(_Int::get(-1));
26+
return;
27+
}
28+
29+
$this->pushToOperandStack(_Int::get(0));
1430
}
1531
}

0 commit comments

Comments
 (0)