@@ -2,17 +2,17 @@ |
||
2 | 2 | |
3 | 3 | namespace Samsara\Fermat\Types; |
4 | 4 | |
5 | -use Ds\Hashable; |
|
6 | -use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState; |
|
7 | -use Samsara\Exceptions\UsageError\IntegrityConstraint; |
|
8 | -use Samsara\Fermat\Numbers; |
|
9 | -use Samsara\Fermat\Provider\ArithmeticProvider; |
|
10 | -use Riimu\Kit\BaseConversion\BaseConverter; |
|
11 | -use Samsara\Fermat\Provider\SequenceProvider; |
|
12 | -use Samsara\Fermat\Provider\SeriesProvider; |
|
13 | -use Samsara\Fermat\Provider\StatsProvider; |
|
14 | -use Samsara\Fermat\Types\Base\DecimalInterface; |
|
15 | -use Samsara\Fermat\Types\Base\NumberInterface; |
|
5 | +use Ds\Hashable; |
|
6 | +use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState; |
|
7 | +use Samsara\Exceptions\UsageError\IntegrityConstraint; |
|
8 | +use Samsara\Fermat\Numbers; |
|
9 | +use Samsara\Fermat\Provider\ArithmeticProvider; |
|
10 | +use Riimu\Kit\BaseConversion\BaseConverter; |
|
11 | +use Samsara\Fermat\Provider\SequenceProvider; |
|
12 | +use Samsara\Fermat\Provider\SeriesProvider; |
|
13 | +use Samsara\Fermat\Provider\StatsProvider; |
|
14 | +use Samsara\Fermat\Types\Base\DecimalInterface; |
|
15 | +use Samsara\Fermat\Types\Base\NumberInterface; |
|
16 | 16 | use Samsara\Fermat\Values\ImmutableNumber; |
17 | 17 | |
18 | 18 | abstract class Number implements Hashable |
@@ -28,6 +28,9 @@ discard block |
||
28 | 28 | |
29 | 29 | protected $extensions = true; |
30 | 30 | |
31 | + /** |
|
32 | + * @param integer $precision |
|
33 | + */ |
|
31 | 34 | public function __construct($value, $precision = null, $base = 10) |
32 | 35 | { |
33 | 36 | $this->base = $base; |
@@ -148,7 +151,7 @@ discard block |
||
148 | 151 | * Note about precision: it uses the smaller of the two precisions (significant figures). |
149 | 152 | * |
150 | 153 | * @param $num |
151 | - * @param $precision |
|
154 | + * @param integer $precision |
|
152 | 155 | * @return DecimalInterface|NumberInterface |
153 | 156 | */ |
154 | 157 | public function divide($num, $precision = null) |
@@ -1011,6 +1014,9 @@ discard block |
||
1011 | 1014 | |
1012 | 1015 | } |
1013 | 1016 | |
1017 | + /** |
|
1018 | + * @param ImmutableNumber $num |
|
1019 | + */ |
|
1014 | 1020 | public function getGreatestCommonDivisor($num) |
1015 | 1021 | { |
1016 | 1022 | /** @var ImmutableNumber $num */ |
@@ -1405,6 +1411,10 @@ discard block |
||
1405 | 1411 | return strpos($this->value, '.'); |
1406 | 1412 | } |
1407 | 1413 | |
1414 | + /** |
|
1415 | + * @param integer $pos |
|
1416 | + * @param integer $add |
|
1417 | + */ |
|
1408 | 1418 | protected function reduceDecimals(array $decimalArray, $pos, $add) |
1409 | 1419 | { |
1410 | 1420 | |
@@ -1454,9 +1464,9 @@ discard block |
||
1454 | 1464 | abstract public function modulo($mod); |
1455 | 1465 | |
1456 | 1466 | /** |
1457 | - * @param $mod |
|
1467 | + * @param NumberInterface $mod |
|
1458 | 1468 | * |
1459 | - * @return NumberInterface|DecimalInterface |
|
1469 | + * @return NumberInterface |
|
1460 | 1470 | */ |
1461 | 1471 | abstract public function continuousModulo($mod); |
1462 | 1472 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | public function __construct($value, $precision = null, $base = 10) |
32 | 32 | { |
33 | 33 | $this->base = $base; |
34 | - $this->value = (string)$value; |
|
34 | + $this->value = (string) $value; |
|
35 | 35 | |
36 | 36 | if (!is_null($precision)) { |
37 | 37 | if ($precision > 2147483646) { |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $curVal = $this->getValue(); |
197 | 197 | $calcVal = Numbers::make(Numbers::IMMUTABLE, 1); |
198 | 198 | |
199 | - for ($i = 1;$i <= $curVal;$i++) { |
|
199 | + for ($i = 1; $i <= $curVal; $i++) { |
|
200 | 200 | $calcVal = $calcVal->multiply($i); |
201 | 201 | } |
202 | 202 | |
@@ -414,15 +414,15 @@ discard block |
||
414 | 414 | |
415 | 415 | $answer = SeriesProvider::maclaurinSeries( |
416 | 416 | $modulo, |
417 | - function ($n) { |
|
417 | + function($n) { |
|
418 | 418 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1, 100); |
419 | 419 | |
420 | 420 | return $negOne->pow($n); |
421 | 421 | }, |
422 | - function ($n) { |
|
422 | + function($n) { |
|
423 | 423 | return SequenceProvider::nthOddNumber($n); |
424 | 424 | }, |
425 | - function ($n) { |
|
425 | + function($n) { |
|
426 | 426 | return SequenceProvider::nthOddNumber($n)->factorial(); |
427 | 427 | }, |
428 | 428 | 0, |
@@ -456,13 +456,13 @@ discard block |
||
456 | 456 | |
457 | 457 | $answer = SeriesProvider::maclaurinSeries( |
458 | 458 | $modulo, |
459 | - function ($n) { |
|
459 | + function($n) { |
|
460 | 460 | return SequenceProvider::nthPowerNegativeOne($n); |
461 | 461 | }, |
462 | - function ($n) { |
|
462 | + function($n) { |
|
463 | 463 | return SequenceProvider::nthEvenNumber($n); |
464 | 464 | }, |
465 | - function ($n) { |
|
465 | + function($n) { |
|
466 | 466 | return SequenceProvider::nthEvenNumber($n)->factorial(); |
467 | 467 | }, |
468 | 468 | 0, |
@@ -547,20 +547,20 @@ discard block |
||
547 | 547 | } else { |
548 | 548 | $answer = SeriesProvider::maclaurinSeries( |
549 | 549 | $modulo, |
550 | - function ($n) { |
|
550 | + function($n) { |
|
551 | 551 | $nthOddNumber = SequenceProvider::nthOddNumber($n); |
552 | 552 | |
553 | 553 | return SequenceProvider::nthEulerZigzag($nthOddNumber); |
554 | 554 | }, |
555 | - function ($n) { |
|
555 | + function($n) { |
|
556 | 556 | |
557 | 557 | return SequenceProvider::nthOddNumber($n); |
558 | 558 | }, |
559 | - function ($n) { |
|
559 | + function($n) { |
|
560 | 560 | return SequenceProvider::nthOddNumber($n)->factorial(); |
561 | 561 | }, |
562 | 562 | 0, |
563 | - $precision + 1 |
|
563 | + $precision+1 |
|
564 | 564 | ); |
565 | 565 | } |
566 | 566 | |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | |
600 | 600 | if ($mod2Pi->isEqual(0)) { |
601 | 601 | return $this->setValue(static::INFINITY); |
602 | - } elseif($modPi->isEqual(0)) { |
|
602 | + } elseif ($modPi->isEqual(0)) { |
|
603 | 603 | return $this->setValue(static::NEG_INFINITY); |
604 | 604 | } |
605 | 605 | |
@@ -1197,7 +1197,7 @@ discard block |
||
1197 | 1197 | |
1198 | 1198 | $rounded = $whole.'.'; |
1199 | 1199 | |
1200 | - for ($i = 0;$i < $decimals;$i++) { |
|
1200 | + for ($i = 0; $i < $decimals; $i++) { |
|
1201 | 1201 | $rounded .= $fractionalArr[$i]; |
1202 | 1202 | } |
1203 | 1203 |