@@ -86,7 +86,7 @@ |
||
| 86 | 86 | if (!$num->isWhole() && !extension_loaded('decimal')) { |
| 87 | 87 | $scale += 1; |
| 88 | 88 | $exponent = $num->multiply($thisNum->ln($scale)); |
| 89 | - return $exponent->exp($scale)->truncateToScale($scale - 1)->getValue(NumberBase::Ten); |
|
| 89 | + return $exponent->exp($scale)->truncateToScale($scale-1)->getValue(NumberBase::Ten); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return ArithmeticProvider::pow($this->asReal(), $num->asReal(), $scale); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @param DecimalInterface $num |
| 17 | 17 | * @return string|false |
| 18 | 18 | */ |
| 19 | - protected function addGMP(DecimalInterface $num): string|false |
|
| 19 | + protected function addGMP(DecimalInterface $num): string | false |
|
| 20 | 20 | { |
| 21 | 21 | if (function_exists('gmp_add') && function_exists('gmp_strval') && $this->extensions) { |
| 22 | 22 | if ($this->isInt() && $num->isInt()) { |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param DecimalInterface $num |
| 34 | 34 | * @return string|false |
| 35 | 35 | */ |
| 36 | - protected function subtractGMP(DecimalInterface $num): string|false |
|
| 36 | + protected function subtractGMP(DecimalInterface $num): string | false |
|
| 37 | 37 | { |
| 38 | 38 | if (function_exists('gmp_sub') && function_exists('gmp_strval') && $this->extensions) { |
| 39 | 39 | if ($this->isInt() && $num->isInt()) { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param DecimalInterface $num |
| 51 | 51 | * @return string|false |
| 52 | 52 | */ |
| 53 | - protected function multiplyGMP(DecimalInterface $num): string|false |
|
| 53 | + protected function multiplyGMP(DecimalInterface $num): string | false |
|
| 54 | 54 | { |
| 55 | 55 | if (function_exists('gmp_mul') && function_exists('gmp_strval') && $this->extensions) { |
| 56 | 56 | if ($this->isInt() && $num->isInt()) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param DecimalInterface $num |
| 68 | 68 | * @return string|false |
| 69 | 69 | */ |
| 70 | - protected function divideGMP(DecimalInterface $num): string|false |
|
| 70 | + protected function divideGMP(DecimalInterface $num): string | false |
|
| 71 | 71 | { |
| 72 | 72 | if (function_exists('gmp_div_qr') && function_exists('gmp_strval') && $this->extensions) { |
| 73 | 73 | if ($this->isInt() && $num->isInt()) { |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @param DecimalInterface $num |
| 92 | 92 | * @return string|false |
| 93 | 93 | */ |
| 94 | - protected function powGMP(DecimalInterface $num): string|false |
|
| 94 | + protected function powGMP(DecimalInterface $num): string | false |
|
| 95 | 95 | { |
| 96 | 96 | if (function_exists('gmp_pow') && function_exists('gmp_strval') && $this->extensions) { |
| 97 | 97 | if ($this->isInt() && $num->isInt() && $num->isPositive()) { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | /** |
| 108 | 108 | * @return string|false |
| 109 | 109 | */ |
| 110 | - protected function sqrtGMP(): string|false |
|
| 110 | + protected function sqrtGMP(): string | false |
|
| 111 | 111 | { |
| 112 | 112 | if (function_exists('gmp_sqrtrem') && function_exists('gmp_strval') && $this->extensions) { |
| 113 | 113 | if ($this->isInt() && $this->isLessThan(PHP_INT_MAX) && $this->isGreaterThan(PHP_INT_MIN)) { |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $curVal = $this->getValue(NumberBase::Ten); |
| 54 | 54 | $calcVal = Numbers::make(Numbers::IMMUTABLE, 1); |
| 55 | 55 | |
| 56 | - for ($i = 1;$i <= $curVal;$i++) { |
|
| 56 | + for ($i = 1; $i <= $curVal; $i++) { |
|
| 57 | 57 | $calcVal = $calcVal->multiply($i); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | if (function_exists('gmp_prob_prime') && $this->extensions) { |
| 250 | - return (bool)gmp_prob_prime($this->getValue(NumberBase::Ten), $certainty); |
|
| 250 | + return (bool) gmp_prob_prime($this->getValue(NumberBase::Ten), $certainty); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | $thisNum = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $this->getScale()); |
@@ -263,13 +263,13 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | $r = $r->subtract(1); |
| 265 | 265 | |
| 266 | - for ($i = 0;$i < $certainty;$i++) { |
|
| 266 | + for ($i = 0; $i < $certainty; $i++) { |
|
| 267 | 267 | $a = RandomProvider::randomInt(2, $s, RandomMode::Speed); |
| 268 | 268 | $x = $a->pow($d)->modulo($thisNum); |
| 269 | 269 | if ($x->isEqual(1) || $x->isEqual($s)) { |
| 270 | 270 | continue; |
| 271 | 271 | } |
| 272 | - for ($j = 0;$j < $r->asInt();$j++) { |
|
| 272 | + for ($j = 0; $j < $r->asInt(); $j++) { |
|
| 273 | 273 | $x = $x->pow(2)->modulo($thisNum); |
| 274 | 274 | if ($x->isEqual($s)) { |
| 275 | 275 | continue 2; |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | } else { |
| 43 | 43 | $x = $this instanceof ImmutableDecimal ? $this : new ImmutableDecimal($this->getValue(NumberBase::Ten)); |
| 44 | 44 | $x2 = $x->pow(2); |
| 45 | - $intScale = $scale + 1; |
|
| 45 | + $intScale = $scale+1; |
|
| 46 | 46 | $terms = $scale; |
| 47 | 47 | $six = new ImmutableDecimal(6); |
| 48 | 48 | |
| 49 | - $aPart = new class($x2, $x) implements ContinuedFractionTermInterface{ |
|
| 49 | + $aPart = new class($x2, $x) implements ContinuedFractionTermInterface { |
|
| 50 | 50 | private ImmutableDecimal $x2; |
| 51 | 51 | private ImmutableDecimal $x; |
| 52 | 52 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | }; |
| 76 | 76 | |
| 77 | - $bPart = new class($x, $six) implements ContinuedFractionTermInterface{ |
|
| 77 | + $bPart = new class($x, $six) implements ContinuedFractionTermInterface { |
|
| 78 | 78 | private ImmutableDecimal $x; |
| 79 | 79 | private ImmutableDecimal $six; |
| 80 | 80 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $answer = $adjustedNum; |
| 183 | 183 | |
| 184 | 184 | if ($exp2) { |
| 185 | - $answer = $answer->add(Numbers::makeNaturalLog2($internalScale + $exp2)->multiply($exp2)); |
|
| 185 | + $answer = $answer->add(Numbers::makeNaturalLog2($internalScale+$exp2)->multiply($exp2)); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | if ($exp1p1) { |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * @throws IntegrityConstraint |
| 25 | 25 | * @throws MissingPackage |
| 26 | 26 | */ |
| 27 | - public function continuousModulo(NumberInterface|string|int|float $mod): DecimalInterface |
|
| 27 | + public function continuousModulo(NumberInterface | string | int | float $mod): DecimalInterface |
|
| 28 | 28 | {
|
| 29 | 29 | |
| 30 | 30 | $mod = Numbers::makeOrDont(Numbers::IMMUTABLE, $mod); |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $thisNum = Numbers::make(Numbers::IMMUTABLE, $this->getValue(NumberBase::Ten), $modScale); |
| 40 | 40 | |
| 41 | - $twoPi = Numbers::make2Pi($modScale + 2); |
|
| 42 | - $pi = Numbers::makePi( $scale + 2 ); |
|
| 41 | + $twoPi = Numbers::make2Pi($modScale+2); |
|
| 42 | + $pi = Numbers::makePi($scale+2); |
|
| 43 | 43 | |
| 44 | 44 | if ($pi->truncate($scale)->isEqual($thisNum->truncate($scale)) || $twoPi->truncate($scale)->isEqual($thisNum->truncate($scale))) { |
| 45 | 45 | return '0'; |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | $answer = SeriesProvider::maclaurinSeries( |
| 53 | 53 | $modulo, |
| 54 | - function ($n) use ($scale, $negOne, $one) { |
|
| 54 | + function($n) use ($scale, $negOne, $one) { |
|
| 55 | 55 | |
| 56 | - return $n % 2 ? $negOne : $one; |
|
| 56 | + return $n%2 ? $negOne : $one; |
|
| 57 | 57 | }, |
| 58 | - function ($n) { |
|
| 58 | + function($n) { |
|
| 59 | 59 | return SequenceProvider::nthOddNumber($n); |
| 60 | 60 | }, |
| 61 | - function ($n) { |
|
| 61 | + function($n) { |
|
| 62 | 62 | return SequenceProvider::nthOddNumber($n)->factorial(); |
| 63 | 63 | }, |
| 64 | 64 | 0, |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | $thisNum = Numbers::make(Numbers::IMMUTABLE, $this->getValue(NumberBase::Ten), $modScale); |
| 90 | 90 | |
| 91 | - $twoPi = Numbers::make2Pi($modScale + 2); |
|
| 92 | - $pi = Numbers::makePi( $intScale ); |
|
| 91 | + $twoPi = Numbers::make2Pi($modScale+2); |
|
| 92 | + $pi = Numbers::makePi($intScale); |
|
| 93 | 93 | |
| 94 | 94 | if ($twoPi->truncate($scale)->isEqual($thisNum->truncate($scale))) { |
| 95 | 95 | return '1'; |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | $answer = SeriesProvider::maclaurinSeries( |
| 107 | 107 | $modulo, |
| 108 | - function ($n) use ($negOne, $one) { |
|
| 108 | + function($n) use ($negOne, $one) { |
|
| 109 | 109 | |
| 110 | - return $n % 2 ? $negOne : $one; |
|
| 110 | + return $n%2 ? $negOne : $one; |
|
| 111 | 111 | }, |
| 112 | - function ($n) use ($intScale) { |
|
| 112 | + function($n) use ($intScale) { |
|
| 113 | 113 | return SequenceProvider::nthEvenNumber($n, $intScale); |
| 114 | 114 | }, |
| 115 | - function ($n) use ($intScale) { |
|
| 115 | + function($n) use ($intScale) { |
|
| 116 | 116 | return SequenceProvider::nthEvenNumber($n, $intScale)->factorial(); |
| 117 | 117 | }, |
| 118 | 118 | 0, |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | protected function tanScale(int $scale = null): string |
| 132 | 132 | { |
| 133 | 133 | $scale = $scale ?? $this->getScale(); |
| 134 | - $intScale = $scale + 3; |
|
| 134 | + $intScale = $scale+3; |
|
| 135 | 135 | if (extension_loaded('decimal')) { |
| 136 | 136 | $intScale = $intScale+$this->numberOfIntDigits(); |
| 137 | 137 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | if ($mod2Pi->isEqual(0)) { |
| 281 | 281 | return static::INFINITY; |
| 282 | - } elseif($modPi->isEqual(0)) { |
|
| 282 | + } elseif ($modPi->isEqual(0)) { |
|
| 283 | 283 | return static::NEG_INFINITY; |
| 284 | 284 | } |
| 285 | 285 | |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | return self::$pi->truncateToScale($digits)->getValue(NumberBase::Ten); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - $internalScale = ($digits*2) + 10; |
|
| 40 | + $internalScale = ($digits*2)+10; |
|
| 41 | 41 | |
| 42 | 42 | $C = Numbers::make(Numbers::IMMUTABLE, '10005', $internalScale)->setMode(CalcMode::Precision)->sqrt($internalScale)->multiply(426880); |
| 43 | 43 | $M = Numbers::make(Numbers::IMMUTABLE, '1', $internalScale)->setMode(CalcMode::Precision); |
| 44 | 44 | $L = Numbers::make(Numbers::IMMUTABLE, '13591409', $internalScale)->setMode(CalcMode::Precision); |
| 45 | 45 | $K = Numbers::make(Numbers::IMMUTABLE, '6', $internalScale)->setMode(CalcMode::Precision); |
| 46 | 46 | $X = Numbers::make(Numbers::IMMUTABLE, '1')->setMode(CalcMode::Precision); |
| 47 | - $sum = Numbers::make(Numbers::MUTABLE,'0', $internalScale + 2)->setMode(CalcMode::Precision); |
|
| 47 | + $sum = Numbers::make(Numbers::MUTABLE, '0', $internalScale+2)->setMode(CalcMode::Precision); |
|
| 48 | 48 | $termNum = 0; |
| 49 | 49 | $one = Numbers::makeOne($internalScale)->setMode(CalcMode::Precision); |
| 50 | 50 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | return self::$e->truncateToScale($digits)->getValue(NumberBase::Ten); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $internalScale = $digits + 3; |
|
| 99 | + $internalScale = $digits+3; |
|
| 100 | 100 | |
| 101 | 101 | $one = Numbers::makeOne($internalScale+5)->setMode(CalcMode::Precision); |
| 102 | 102 | $denominator = Numbers::make(Numbers::MUTABLE, '1', $internalScale)->setMode(CalcMode::Precision); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $this->base = $base; |
| 51 | 51 | |
| 52 | - $value = $value instanceof NumberInterface ? $value->getValue(NumberBase::Ten) : (string)$value; |
|
| 52 | + $value = $value instanceof NumberInterface ? $value->getValue(NumberBase::Ten) : (string) $value; |
|
| 53 | 53 | |
| 54 | 54 | if (str_contains($value, 'i')) { |
| 55 | 55 | $this->imaginary = true; |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | if ($exp > 0) { |
| 108 | 108 | $exp -= strlen($right); |
| 109 | 109 | if ($exp >= 0) { |
| 110 | - $right = str_pad($right, $exp - 1, '0').'.0'; |
|
| 110 | + $right = str_pad($right, $exp-1, '0').'.0'; |
|
| 111 | 111 | } else { |
| 112 | - $right = substr($right, 0, strlen($right) + abs($exp)).'.'.substr($right, strlen($right) + abs($exp) + 1); |
|
| 112 | + $right = substr($right, 0, strlen($right)+abs($exp)).'.'.substr($right, strlen($right)+abs($exp)+1); |
|
| 113 | 113 | } |
| 114 | 114 | } else { |
| 115 | 115 | $exp += strlen($left); |
| 116 | 116 | if ($exp >= 0) { |
| 117 | - $left = substr($left, 0, $exp).'.'.substr($left, $exp + 1); |
|
| 117 | + $left = substr($left, 0, $exp).'.'.substr($left, $exp+1); |
|
| 118 | 118 | } else { |
| 119 | 119 | $left = '0.'.str_pad($left, abs($exp)+1, '0', STR_PAD_LEFT); |
| 120 | 120 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @param NumberBase $base |
| 260 | 260 | * @return DecimalInterface|NumberInterface |
| 261 | 261 | */ |
| 262 | - public function setBase(NumberBase $base): DecimalInterface|NumberInterface |
|
| 262 | + public function setBase(NumberBase $base): DecimalInterface | NumberInterface |
|
| 263 | 263 | { |
| 264 | 264 | $this->base = $base; |
| 265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | * @return DecimalInterface|NumberInterface |
| 273 | 273 | */ |
| 274 | - public function abs(): DecimalInterface|NumberInterface |
|
| 274 | + public function abs(): DecimalInterface | NumberInterface |
|
| 275 | 275 | { |
| 276 | 276 | $newValue = $this->absValue(); |
| 277 | 277 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @param DecimalInterface $num |
| 283 | 283 | * @return float|int |
| 284 | 284 | */ |
| 285 | - protected static function translateToNative(DecimalInterface $num): float|int |
|
| 285 | + protected static function translateToNative(DecimalInterface $num): float | int |
|
| 286 | 286 | { |
| 287 | 287 | return ($num->isInt() ? $num->asInt() : $num->asFloat()); |
| 288 | 288 | } |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * @param NumberInterface|string|int|float $mod |
| 342 | 342 | * @return DecimalInterface |
| 343 | 343 | */ |
| 344 | - abstract public function continuousModulo(NumberInterface|string|int|float $mod): DecimalInterface; |
|
| 344 | + abstract public function continuousModulo(NumberInterface | string | int | float $mod): DecimalInterface; |
|
| 345 | 345 | |
| 346 | 346 | /** |
| 347 | 347 | * @param string $decimalPart |
@@ -105,8 +105,8 @@ |
||
| 105 | 105 | $runningTotal = Numbers::make(Numbers::IMMUTABLE, $startVal->getAsBaseTenRealNumber()); |
| 106 | 106 | while ($runningTotal->isGreaterThan(0)) { |
| 107 | 107 | $current = gmp_div_qr($runningTotal->getAsBaseTenRealNumber(), $baseNum->getAsBaseTenRealNumber()); |
| 108 | - $mod = (int)$current[1]; |
|
| 109 | - $stringVal = self::$chars[$mod] . $stringVal; |
|
| 108 | + $mod = (int) $current[1]; |
|
| 109 | + $stringVal = self::$chars[$mod].$stringVal; |
|
| 110 | 110 | $runningTotal = Numbers::make(Numbers::IMMUTABLE, $current[0]); |
| 111 | 111 | } |
| 112 | 112 | } else { |