Passed
Push — dev ( 3795a8...3f4d81 )
by Jordan
14:20
created

ImmutableNumber::isComplex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Samsara\Fermat\Values;
4
5
use Samsara\Fermat\Numbers;
6
use Samsara\Fermat\Types\Number;
7
use Samsara\Fermat\Types\Base\DecimalInterface;
8
use Samsara\Fermat\Types\Base\NumberInterface;
9
10
class ImmutableNumber extends Number implements NumberInterface, DecimalInterface
11
{
12
13 5
    public function modulo($mod)
14
    {
15 5
        $oldBase = $this->convertForModification();
16
17 5
        return (new ImmutableNumber(bcmod($this->getValue(), $mod), $this->getPrecision(), $this->getBase()))->convertFromModification($oldBase);
18
    }
19
20 7
    public function continuousModulo($mod)
21
    {
22
23 7
        if (is_object($mod) && method_exists($mod, 'getPrecision')) {
24 6
            $precision = ($this->getPrecision() < $mod->getPrecision()) ? $mod->getPrecision() : $this->getPrecision();
25
        } else {
26 1
            $precision = $this->getPrecision();
27
        }
28
29 7
        $oldPrecision = $this->precision;
30 7
        $newPrecision = $precision+1;
31
32 7
        $this->precision = $newPrecision;
33
34 7
        if (is_object($mod) && method_exists($mod, 'truncateToPrecision')) {
35 6
            $mod = $mod->truncateToPrecision($newPrecision);
36
        } else {
37 1
            $mod = Numbers::make(Numbers::IMMUTABLE, $mod, $newPrecision);
38
        }
39
40 7
        $multiple = $this->divide($mod)->floor();
41
42 7
        $remainder = $this->subtract($mod->multiply($multiple));
43
44 7
        $this->precision = $oldPrecision;
45
46 7
        return $remainder->truncateToPrecision($oldPrecision);
47
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function isComplex(): bool
54
    {
55 69
        return false;
56
    }
57 69
58
    /**
59
     * @param $value
60
     *
61
     * @return ImmutableNumber
62
     */
63
    protected function setValue($value)
64
    {
65
        return new ImmutableNumber($value, $this->getPrecision(), $this->getBase());
66
    }
67
68
}