@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $curVal = $this->getValue(); |
| 34 | 34 | $calcVal = Numbers::make(Numbers::IMMUTABLE, 1); |
| 35 | 35 | |
| 36 | - for ($i = 1;$i <= $curVal;$i++) { |
|
| 36 | + for ($i = 1; $i <= $curVal; $i++) { |
|
| 37 | 37 | $calcVal = $calcVal->multiply($i); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | $this->base = $base; |
| 39 | 39 | |
| 40 | - $value = (string)$value; |
|
| 40 | + $value = (string) $value; |
|
| 41 | 41 | |
| 42 | 42 | if (strpos($value, 'i') !== false) { |
| 43 | 43 | $this->imaginary = true; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $this->scale = ($scale > strlen($this->getDecimalPart())) ? $scale : strlen($this->getDecimalPart()); |
| 65 | 65 | } else { |
| 66 | 66 | $checkVal = $this->getDecimalPart(); |
| 67 | - $checkVal = trim($checkVal,'0'); |
|
| 67 | + $checkVal = trim($checkVal, '0'); |
|
| 68 | 68 | |
| 69 | 69 | if (strlen($checkVal) > 0) { |
| 70 | 70 | $this->scale = (strlen($this->getDecimalPart()) > 10) ? strlen($this->getDecimalPart()) : 10; |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | if ($exp > 0) { |
| 103 | 103 | $exp -= strlen($right); |
| 104 | 104 | if ($exp >= 0) { |
| 105 | - $right = str_pad($right, $exp - 1, '0').'.0'; |
|
| 105 | + $right = str_pad($right, $exp-1, '0').'.0'; |
|
| 106 | 106 | } else { |
| 107 | - $right = substr($right, 0, strlen($right) + $exp).'.'.substr($right, strlen($right) + $exp + 1); |
|
| 107 | + $right = substr($right, 0, strlen($right)+$exp).'.'.substr($right, strlen($right)+$exp+1); |
|
| 108 | 108 | } |
| 109 | 109 | } else { |
| 110 | 110 | $exp += strlen($left); |
| 111 | 111 | if ($exp >= 0) { |
| 112 | - $left = substr($left, 0, $exp).'.'.substr($left, $exp + 1); |
|
| 112 | + $left = substr($left, 0, $exp).'.'.substr($left, $exp+1); |
|
| 113 | 113 | } else { |
| 114 | 114 | $left = '0.'.str_pad($left, $exp, '0', STR_PAD_LEFT); |
| 115 | 115 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | if (!$num->isWhole()) { |
| 71 | 71 | $scale += 5; |
| 72 | 72 | $exponent = $num->multiply($this->ln($scale)); |
| 73 | - return $exponent->exp($scale)->truncateToScale($scale - 5)->getValue(); |
|
| 73 | + return $exponent->exp($scale)->truncateToScale($scale-5)->getValue(); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | return ArithmeticProvider::pow($this->asReal(), $num->asReal(), $scale); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | } elseif ($this->isEqual(0)) { |
| 28 | 28 | $answer = Numbers::makeZero(); |
| 29 | 29 | } else { |
| 30 | - $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale + 2); |
|
| 30 | + $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale+2); |
|
| 31 | 31 | $one = Numbers::makeOne($scale+2); |
| 32 | 32 | |
| 33 | 33 | if ($z->abs()->isGreaterThan(1)) { |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | } elseif ($this->isEqual(1)) { |
| 78 | 78 | $answer = Numbers::makeZero(); |
| 79 | 79 | } else { |
| 80 | - $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale + 2); |
|
| 81 | - $one = Numbers::makeOne($scale + 2); |
|
| 80 | + $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale+2); |
|
| 81 | + $one = Numbers::makeOne($scale+2); |
|
| 82 | 82 | |
| 83 | 83 | if ($z->abs()->isGreaterThan(1)) { |
| 84 | 84 | throw new IntegrityConstraint( |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | $scale = $scale ?? $this->getScale(); |
| 130 | 130 | |
| 131 | - $piDivTwo = Numbers::makePi($scale + 2)->divide(2, $scale + 2); |
|
| 131 | + $piDivTwo = Numbers::makePi($scale+2)->divide(2, $scale+2); |
|
| 132 | 132 | |
| 133 | - $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale + 2); |
|
| 133 | + $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale+2); |
|
| 134 | 134 | |
| 135 | 135 | $arctan = $z->arctan($scale+2, false); |
| 136 | 136 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | $scale = $scale ?? $this->getScale(); |
| 153 | 153 | |
| 154 | - $one = Numbers::makeOne($scale + 2); |
|
| 154 | + $one = Numbers::makeOne($scale+2); |
|
| 155 | 155 | $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale+2); |
| 156 | 156 | |
| 157 | 157 | if ($z->abs()->isLessThan(1)) { |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $answer = $one->divide($z, $scale + 2)->arccos($scale + 2); |
|
| 165 | + $answer = $one->divide($z, $scale+2)->arccos($scale+2); |
|
| 166 | 166 | |
| 167 | 167 | if ($round) { |
| 168 | 168 | $answer = $answer->roundToScale($scale); |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | $scale = $scale ?? $this->getScale(); |
| 181 | 181 | |
| 182 | - $one = Numbers::makeOne($scale + 2); |
|
| 182 | + $one = Numbers::makeOne($scale+2); |
|
| 183 | 183 | $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $this, $scale+2); |
| 184 | 184 | |
| 185 | 185 | if ($z->abs()->isLessThan(1)) { |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - $answer = $one->divide($z, $scale + 2)->arcsin($scale + 2); |
|
| 193 | + $answer = $one->divide($z, $scale+2)->arcsin($scale+2); |
|
| 194 | 194 | |
| 195 | 195 | if ($round) { |
| 196 | 196 | $answer = $answer->roundToScale($scale); |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | $answer = SeriesProvider::maclaurinSeries( |
| 31 | 31 | $modulo, |
| 32 | - function ($n) { |
|
| 32 | + function($n) { |
|
| 33 | 33 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1, 100); |
| 34 | 34 | |
| 35 | 35 | return $negOne->pow($n); |
| 36 | 36 | }, |
| 37 | - function ($n) { |
|
| 37 | + function($n) { |
|
| 38 | 38 | return SequenceProvider::nthOddNumber($n); |
| 39 | 39 | }, |
| 40 | - function ($n) { |
|
| 40 | + function($n) { |
|
| 41 | 41 | return SequenceProvider::nthOddNumber($n)->factorial(); |
| 42 | 42 | }, |
| 43 | 43 | 0, |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | $answer = SeriesProvider::maclaurinSeries( |
| 76 | 76 | $modulo, |
| 77 | - function ($n) { |
|
| 77 | + function($n) { |
|
| 78 | 78 | return SequenceProvider::nthPowerNegativeOne($n); |
| 79 | 79 | }, |
| 80 | - function ($n) { |
|
| 80 | + function($n) { |
|
| 81 | 81 | return SequenceProvider::nthEvenNumber($n); |
| 82 | 82 | }, |
| 83 | - function ($n) { |
|
| 83 | + function($n) { |
|
| 84 | 84 | return SequenceProvider::nthEvenNumber($n)->factorial(); |
| 85 | 85 | }, |
| 86 | 86 | 0, |
@@ -159,20 +159,20 @@ discard block |
||
| 159 | 159 | } else { |
| 160 | 160 | $answer = SeriesProvider::maclaurinSeries( |
| 161 | 161 | $modulo, |
| 162 | - function ($n) { |
|
| 162 | + function($n) { |
|
| 163 | 163 | $nthOddNumber = SequenceProvider::nthOddNumber($n); |
| 164 | 164 | |
| 165 | 165 | return SequenceProvider::nthEulerZigzag($nthOddNumber->asInt()); |
| 166 | 166 | }, |
| 167 | - function ($n) { |
|
| 167 | + function($n) { |
|
| 168 | 168 | |
| 169 | 169 | return SequenceProvider::nthOddNumber($n); |
| 170 | 170 | }, |
| 171 | - function ($n) { |
|
| 171 | + function($n) { |
|
| 172 | 172 | return SequenceProvider::nthOddNumber($n)->factorial(); |
| 173 | 173 | }, |
| 174 | 174 | 0, |
| 175 | - $scale + 1 |
|
| 175 | + $scale+1 |
|
| 176 | 176 | ); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | if ($mod2Pi->isEqual(0)) { |
| 207 | 207 | return $this->setValue(static::INFINITY); |
| 208 | - } elseif($modPi->isEqual(0)) { |
|
| 208 | + } elseif ($modPi->isEqual(0)) { |
|
| 209 | 209 | return $this->setValue(static::NEG_INFINITY); |
| 210 | 210 | } |
| 211 | 211 | |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | public static function makePi(int $digits): string |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - $internalScale = $digits + 10; |
|
| 17 | + $internalScale = $digits+10; |
|
| 18 | 18 | |
| 19 | 19 | $C = Numbers::make(Numbers::IMMUTABLE, '10005', $internalScale)->sqrt($internalScale)->multiply(426880); |
| 20 | 20 | $M = Numbers::make(Numbers::IMMUTABLE, '1', $internalScale); |
| 21 | 21 | $L = Numbers::make(Numbers::IMMUTABLE, '13591409', $internalScale); |
| 22 | 22 | $K = Numbers::make(Numbers::IMMUTABLE, '6', $internalScale); |
| 23 | 23 | $X = Numbers::make(Numbers::IMMUTABLE, '1'); |
| 24 | - $sum = Numbers::make(Numbers::MUTABLE,'0', $internalScale + 2); |
|
| 24 | + $sum = Numbers::make(Numbers::MUTABLE, '0', $internalScale+2); |
|
| 25 | 25 | $termNum = 0; |
| 26 | 26 | $one = Numbers::makeOne($internalScale); |
| 27 | 27 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | public static function makeE(int $digits): string |
| 68 | 68 | { |
| 69 | 69 | |
| 70 | - $internalScale = $digits + 3; |
|
| 70 | + $internalScale = $digits+3; |
|
| 71 | 71 | |
| 72 | 72 | $one = Numbers::makeOne($internalScale+5)->setMode(Selectable::CALC_MODE_PRECISION); |
| 73 | 73 | $denominator = Numbers::make(Numbers::MUTABLE, '1', $internalScale)->setMode(Selectable::CALC_MODE_PRECISION); |
@@ -17,9 +17,9 @@ discard block |
||
| 17 | 17 | public static function radiansToDegrees($radians) |
| 18 | 18 | { |
| 19 | 19 | $radians = Numbers::makeOrDont(Numbers::IMMUTABLE, $radians); |
| 20 | - $pi = Numbers::makePi($radians->getScale() + 2); |
|
| 20 | + $pi = Numbers::makePi($radians->getScale()+2); |
|
| 21 | 21 | |
| 22 | - return $radians->multiply(180)->divide($pi, $radians->getScale() + 2)->round($radians->getScale() - 2)->getValue(); |
|
| 22 | + return $radians->multiply(180)->divide($pi, $radians->getScale()+2)->round($radians->getScale()-2)->getValue(); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public static function degreesToRadians($degrees) |
| 32 | 32 | { |
| 33 | 33 | $degrees = Numbers::makeOrDont(Numbers::IMMUTABLE, $degrees); |
| 34 | - $pi = Numbers::makePi($degrees->getScale() + 1); |
|
| 34 | + $pi = Numbers::makePi($degrees->getScale()+1); |
|
| 35 | 35 | |
| 36 | 36 | return $degrees->multiply($pi)->divide(180)->round($degrees->getScale())->getValue(); |
| 37 | 37 | } |
@@ -237,7 +237,7 @@ |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | if ($scale > 100) {
|
| 240 | - $pi = self::make(self::IMMUTABLE, ConstantProvider::makePi($scale), $scale + 2); |
|
| 240 | + $pi = self::make(self::IMMUTABLE, ConstantProvider::makePi($scale), $scale+2); |
|
| 241 | 241 | return $pi->multiply(2)->truncateToScale($scale); |
| 242 | 242 | } |
| 243 | 243 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | protected function addSelector(DecimalInterface $num) |
| 142 | 142 | { |
| 143 | - return match ($this->calcMode) { |
|
| 143 | + return match($this->calcMode) { |
|
| 144 | 144 | Selectable::CALC_MODE_PRECISION => $this->addScale($num), |
| 145 | 145 | Selectable::CALC_MODE_NATIVE => $this->addNative($num), |
| 146 | 146 | default => $this->{$this->modeRegister[Selectable::CALC_MODE_FALLBACK]['add']}($num), |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | protected function subtractSelector(DecimalInterface $num) |
| 151 | 151 | { |
| 152 | - return match ($this->calcMode) { |
|
| 152 | + return match($this->calcMode) { |
|
| 153 | 153 | Selectable::CALC_MODE_PRECISION => $this->subtractScale($num), |
| 154 | 154 | Selectable::CALC_MODE_NATIVE => $this->subtractNative($num), |
| 155 | 155 | default => $this->{$this->modeRegister[Selectable::CALC_MODE_FALLBACK]['subtract']}($num), |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | protected function multiplySelector(DecimalInterface $num) |
| 160 | 160 | { |
| 161 | - return match ($this->calcMode) { |
|
| 161 | + return match($this->calcMode) { |
|
| 162 | 162 | Selectable::CALC_MODE_PRECISION => $this->multiplyScale($num), |
| 163 | 163 | Selectable::CALC_MODE_NATIVE => $this->multiplyNative($num), |
| 164 | 164 | default => $this->{$this->modeRegister[Selectable::CALC_MODE_FALLBACK]['multiply']}($num), |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | protected function divideSelector(DecimalInterface $num, int $scale) |
| 169 | 169 | { |
| 170 | - return match ($this->calcMode) { |
|
| 170 | + return match($this->calcMode) { |
|
| 171 | 171 | Selectable::CALC_MODE_PRECISION => $this->divideScale($num, $scale), |
| 172 | 172 | Selectable::CALC_MODE_NATIVE => $this->divideNative($num), |
| 173 | 173 | default => $this->{$this->modeRegister[Selectable::CALC_MODE_FALLBACK]['divide']}($num, $scale), |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | protected function powSelector(DecimalInterface $num) |
| 178 | 178 | { |
| 179 | - return match ($this->calcMode) { |
|
| 179 | + return match($this->calcMode) { |
|
| 180 | 180 | Selectable::CALC_MODE_PRECISION => $this->powScale($num), |
| 181 | 181 | Selectable::CALC_MODE_NATIVE => $this->powNative($num), |
| 182 | 182 | default => $this->{$this->modeRegister[Selectable::CALC_MODE_FALLBACK]['pow']}($num), |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | protected function sqrtSelector(int $scale) |
| 187 | 187 | { |
| 188 | - return match ($this->calcMode) { |
|
| 188 | + return match($this->calcMode) { |
|
| 189 | 189 | Selectable::CALC_MODE_PRECISION => $this->sqrtScale($scale), |
| 190 | 190 | Selectable::CALC_MODE_NATIVE => $this->sqrtNative(), |
| 191 | 191 | default => $this->{$this->modeRegister[Selectable::CALC_MODE_FALLBACK]['sqrt']}($scale), |