1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Samsara\Fermat\Values;
|
4
|
|
|
|
5
|
|
|
use Samsara\Fermat\Numbers;
|
6
|
|
|
use Samsara\Fermat\Types\Decimal;
|
7
|
|
|
use Samsara\Fermat\Types\Base\Interfaces\Numbers\DecimalInterface;
|
8
|
|
|
|
9
|
|
|
class ImmutableDecimal extends Decimal
|
10
|
|
|
{
|
11
|
|
|
|
12
|
23 |
|
public function continuousModulo($mod): DecimalInterface
|
13
|
|
|
{
|
14
|
|
|
|
15
|
23 |
|
if (is_object($mod) && method_exists($mod, 'getPrecision')) {
|
16
|
22 |
|
$precision = ($this->getPrecision() < $mod->getPrecision()) ? $mod->getPrecision() : $this->getPrecision();
|
17
|
|
|
} else {
|
18
|
11 |
|
$precision = $this->getPrecision();
|
19
|
|
|
}
|
20
|
|
|
|
21
|
23 |
|
$oldPrecision = $this->precision;
|
22
|
23 |
|
$newPrecision = $precision+1;
|
23
|
|
|
|
24
|
23 |
|
$this->precision = $newPrecision;
|
25
|
|
|
|
26
|
23 |
|
if (is_object($mod) && method_exists($mod, 'truncateToPrecision')) {
|
27
|
22 |
|
$mod = $mod->truncateToPrecision($newPrecision);
|
28
|
|
|
} else {
|
29
|
11 |
|
$mod = Numbers::make(Numbers::IMMUTABLE, $mod, $newPrecision);
|
30
|
|
|
}
|
31
|
|
|
|
32
|
23 |
|
$multiple = $this->divide($mod)->floor();
|
33
|
|
|
|
34
|
23 |
|
$remainder = $this->subtract($mod->multiply($multiple));
|
35
|
|
|
|
36
|
23 |
|
$this->precision = $oldPrecision;
|
37
|
|
|
|
38
|
23 |
|
return $remainder->truncateToPrecision($oldPrecision);
|
|
|
|
|
39
|
|
|
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
/**
|
43
|
|
|
* @return bool
|
44
|
|
|
*/
|
45
|
94 |
|
public function isComplex(): bool
|
46
|
|
|
{
|
47
|
94 |
|
return false;
|
48
|
|
|
}
|
49
|
|
|
|
50
|
|
|
/**
|
51
|
|
|
* @param string $value
|
52
|
|
|
* @param int|null $precision
|
53
|
|
|
* @param int $base
|
54
|
|
|
*
|
55
|
|
|
* @return ImmutableDecimal
|
56
|
|
|
*/
|
57
|
110 |
|
protected function setValue(string $value, int $precision = null, int $base = 10)
|
58
|
|
|
{
|
59
|
110 |
|
$imaginary = false;
|
60
|
|
|
|
61
|
110 |
|
$precision = $precision ?? $this->getPrecision();
|
62
|
|
|
|
63
|
110 |
|
if (strpos($value, 'i') !== false) {
|
64
|
8 |
|
$value = str_replace('i', '', $value);
|
65
|
8 |
|
$imaginary = true;
|
66
|
|
|
}
|
67
|
|
|
|
68
|
110 |
|
if ($base !== 10 || $this->getBase() !== 10) {
|
69
|
3 |
|
$base = $base === 10 ? $this->getBase() : $base;
|
70
|
3 |
|
$value = $this->convertValue($value, 10, $base);
|
71
|
|
|
}
|
72
|
|
|
|
73
|
110 |
|
if ($imaginary) {
|
74
|
8 |
|
$value .= 'i';
|
75
|
|
|
}
|
76
|
|
|
|
77
|
110 |
|
return new ImmutableDecimal($value, $precision, $base);
|
78
|
|
|
}
|
79
|
|
|
|
80
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.