-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddition.php
More file actions
37 lines (27 loc) · 1.11 KB
/
Addition.php
File metadata and controls
37 lines (27 loc) · 1.11 KB
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 TinyBlocks\Math\Internal\Operations\Adapters\Scales;
use TinyBlocks\Math\BigNumber;
use TinyBlocks\Math\Internal\Scale;
final readonly class Addition implements Scales
{
private Scale $augendScale;
private Scale $addendScale;
public function __construct(private BigNumber $augend, private BigNumber $addend)
{
$this->augendScale = Scale::from(value: $this->augend->getScale());
$this->addendScale = Scale::from(value: $this->addend->getScale());
}
public function applyScale(): Scale
{
if ($this->augendScale->hasAutomaticScale() && $this->addendScale->hasAutomaticScale()) {
$augendScale = $this->augendScale->scaleOf(value: $this->augend->toString());
$addendScale = $this->addendScale->scaleOf(value: $this->addend->toString());
if ($augendScale->equals(other: $addendScale)) {
return $augendScale;
}
return $augendScale->greaterScale(other: $addendScale);
}
return $this->augendScale->greaterScale(other: $this->addendScale);
}
}