@@ -25,6 +25,6 @@ |
||
25 | 25 | return $sample; |
26 | 26 | } |
27 | 27 | |
28 | - abstract public function rangeRandom($min = 0, $max = PHP_INT_MAX, int $maxIterations = 20): ImmutableDecimal; |
|
28 | + abstract public function rangeRandom($min = 0, $max = PHP_INT_MAX, int $maxIterations = 20): ImmutableDecimal; |
|
29 | 29 | |
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -80,7 +80,7 @@ |
||
80 | 80 | $e = Numbers::makeE($scale); |
81 | 81 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
82 | 82 | |
83 | - $internalScale = (new NumberCollection([$scale, $x]))->selectScale() + 2; |
|
83 | + $internalScale = (new NumberCollection([$scale, $x]))->selectScale()+2; |
|
84 | 84 | |
85 | 85 | // $left = 1 / ( sqrt(2pi * SD^2) ) |
86 | 86 | $left = |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @throws IntegrityConstraint |
64 | 64 | * @throws IncompatibleObjectState |
65 | 65 | */ |
66 | - public function cdf(int|float|DecimalInterface $x, int $scale = 10): ImmutableDecimal |
|
66 | + public function cdf(int | float | DecimalInterface $x, int $scale = 10): ImmutableDecimal |
|
67 | 67 | { |
68 | 68 | |
69 | 69 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ); |
77 | 77 | } |
78 | 78 | |
79 | - $internalScale = $scale + 2; |
|
79 | + $internalScale = $scale+2; |
|
80 | 80 | |
81 | 81 | $cumulative = Numbers::makeZero(); |
82 | 82 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @throws IntegrityConstraint |
102 | 102 | * @throws IncompatibleObjectState |
103 | 103 | */ |
104 | - public function pmf(float|int|DecimalInterface $x, int $scale = 10): ImmutableDecimal |
|
104 | + public function pmf(float | int | DecimalInterface $x, int $scale = 10): ImmutableDecimal |
|
105 | 105 | { |
106 | 106 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
107 | 107 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ); |
114 | 114 | } |
115 | 115 | |
116 | - $internalScale = $scale + 2; |
|
116 | + $internalScale = $scale+2; |
|
117 | 117 | |
118 | 118 | $e = Numbers::makeE($internalScale); |
119 | 119 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | while (true) { |
260 | 260 | /** @var ImmutableDecimal $u */ |
261 | - $u = PolyfillProvider::randomInt(0, PHP_INT_MAX) / PHP_INT_MAX; |
|
261 | + $u = PolyfillProvider::randomInt(0, PHP_INT_MAX)/PHP_INT_MAX; |
|
262 | 262 | /** @var ImmutableDecimal $x */ |
263 | 263 | $x = $alpha->subtract($one->subtract($u)->divide($u)->ln(20)->divide($beta)); |
264 | 264 | /** @var ImmutableDecimal $n */ |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | ->multiply($e->pow($eExponent)) |
54 | 54 | ->multiply(SeriesProvider::maclaurinSeries( |
55 | 55 | $x, |
56 | - function ($n) { |
|
56 | + function($n) { |
|
57 | 57 | return Numbers::makeOne(); |
58 | 58 | }, |
59 | - function ($n) { |
|
59 | + function($n) { |
|
60 | 60 | return SequenceProvider::nthOddNumber($n); |
61 | 61 | }, |
62 | - function ($n) { |
|
62 | + function($n) { |
|
63 | 63 | return SequenceProvider::nthOddNumber($n)->doubleFactorial(); |
64 | 64 | }, |
65 | 65 | 0, |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x); |
103 | 103 | |
104 | 104 | $scale = $x->getScale(); |
105 | - $internalScale = $scale + 2; |
|
105 | + $internalScale = $scale+2; |
|
106 | 106 | |
107 | 107 | $answer = Numbers::makeOne($internalScale); |
108 | 108 | $pi = Numbers::makePi($internalScale); |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | $answer = $answer->multiply( |
113 | 113 | SeriesProvider::maclaurinSeries( |
114 | 114 | $x, |
115 | - function ($n) { |
|
115 | + function($n) { |
|
116 | 116 | $negOne = Numbers::make(Numbers::IMMUTABLE, -1); |
117 | 117 | |
118 | 118 | return $negOne->pow($n); |
119 | 119 | }, |
120 | - function ($n) { |
|
120 | + function($n) { |
|
121 | 121 | return SequenceProvider::nthOddNumber($n); |
122 | 122 | }, |
123 | - function ($n) { |
|
123 | + function($n) { |
|
124 | 124 | $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n); |
125 | 125 | |
126 | 126 | return $n->factorial()->multiply(SequenceProvider::nthOddNumber($n->asInt())); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $p = Numbers::makeOrDont(Numbers::IMMUTABLE, $p); |
150 | 150 | |
151 | 151 | $scale = $scale ?? $p->getScale(); |
152 | - $internalScale = $scale + $p->numberOfDecimalDigits(); |
|
152 | + $internalScale = $scale+$p->numberOfDecimalDigits(); |
|
153 | 153 | |
154 | 154 | $two = Numbers::make(Numbers::IMMUTABLE, 2, $internalScale); |
155 | 155 | $invErfArg = $two->multiply($p)->subtract(1); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | static::$inverseErrorCoefs->push(new ImmutableFraction(Numbers::makeOne(), Numbers::makeOne())); |
201 | 201 | } |
202 | 202 | |
203 | - $terms =& static::$inverseErrorCoefs; |
|
203 | + $terms = & static::$inverseErrorCoefs; |
|
204 | 204 | |
205 | 205 | if ($terms->offsetExists($termIndex)) { |
206 | 206 | return $terms->get($termIndex); |
@@ -210,11 +210,11 @@ discard block |
||
210 | 210 | |
211 | 211 | for ($k = $nextTerm;$k <= $termIndex;$k++) { |
212 | 212 | $termValue = new ImmutableFraction(new ImmutableDecimal('0'), new ImmutableDecimal('1')); |
213 | - for ($m = 0;$m <= ($k - 1);$m++) { |
|
213 | + for ($m = 0;$m <= ($k-1);$m++) { |
|
214 | 214 | $part1 = $terms->get($m); |
215 | - $part2 = $terms->get($k - 1 - $m); |
|
215 | + $part2 = $terms->get($k-1-$m); |
|
216 | 216 | $part3 = $part1->multiply($part2); |
217 | - $part4 = ($m + 1)*($m*2 + 1); |
|
217 | + $part4 = ($m+1)*($m*2+1); |
|
218 | 218 | $part5 = $part3->divide($part4); |
219 | 219 | $termValue = $termValue->add($part5); |
220 | 220 | } |
@@ -243,23 +243,23 @@ discard block |
||
243 | 243 | $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $z); |
244 | 244 | |
245 | 245 | $scale = $scale ?? $z->getScale(); |
246 | - $internalScale = $scale + $z->numberOfDecimalDigits(); |
|
246 | + $internalScale = $scale+$z->numberOfDecimalDigits(); |
|
247 | 247 | |
248 | 248 | $pi = Numbers::makePi($internalScale); |
249 | 249 | |
250 | 250 | $answer = SeriesProvider::maclaurinSeries( |
251 | 251 | $z, |
252 | - static function ($n) use ($pi) { |
|
252 | + static function($n) use ($pi) { |
|
253 | 253 | if ($n > 0) { |
254 | 254 | return $pi->pow($n)->multiply(StatsProvider::inverseErrorCoefficients($n)); |
255 | 255 | } |
256 | 256 | |
257 | 257 | return Numbers::makeOne(); |
258 | 258 | }, |
259 | - static function ($n) { |
|
259 | + static function($n) { |
|
260 | 260 | return SequenceProvider::nthOddNumber($n); |
261 | 261 | }, |
262 | - static function ($n) { |
|
262 | + static function($n) { |
|
263 | 263 | if ($n > 0) { |
264 | 264 | $extra = Numbers::make(Numbers::IMMUTABLE, 2)->pow(SequenceProvider::nthEvenNumber($n)); |
265 | 265 | } else { |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * |
25 | 25 | * @return DecimalInterface |
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 | * @param $num |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | $e = Numbers::makeE($scale+$addScale); |
49 | 49 | $value = $e->pow($this); |
50 | 50 | } else { |
51 | - $intScale = ($this->numberOfIntDigits()) ? ($scale + 2) * $this->numberOfIntDigits() : ($scale + 2); |
|
52 | - $intScale = ($this->numberOfLeadingZeros()) ? $intScale * $this->numberOfLeadingZeros() : $intScale; |
|
51 | + $intScale = ($this->numberOfIntDigits()) ? ($scale+2)*$this->numberOfIntDigits() : ($scale+2); |
|
52 | + $intScale = ($this->numberOfLeadingZeros()) ? $intScale*$this->numberOfLeadingZeros() : $intScale; |
|
53 | 53 | $x = $this instanceof ImmutableDecimal ? $this : new ImmutableDecimal($this->getValue(NumberBase::Ten), $intScale); |
54 | 54 | $x2 = $x->pow(2); |
55 | 55 | $terms = $scale; |
56 | 56 | $six = new ImmutableDecimal(6, $intScale); |
57 | 57 | |
58 | - $aPart = new class($x2, $x) implements ContinuedFractionTermInterface{ |
|
58 | + $aPart = new class($x2, $x) implements ContinuedFractionTermInterface { |
|
59 | 59 | private ImmutableDecimal $x2; |
60 | 60 | private ImmutableDecimal $x; |
61 | 61 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | }; |
85 | 85 | |
86 | - $bPart = new class($x, $six, $intScale) implements ContinuedFractionTermInterface{ |
|
86 | + $bPart = new class($x, $six, $intScale) implements ContinuedFractionTermInterface { |
|
87 | 87 | private ImmutableDecimal $x; |
88 | 88 | private ImmutableDecimal $six; |
89 | 89 | private int $intScale; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | protected function lnScale(int $scale = null): string |
134 | 134 | { |
135 | 135 | $internalScale = $scale ?? $this->getScale(); |
136 | - $internalScale += 3 + $this->numberOfLeadingZeros(); |
|
136 | + $internalScale += 3+$this->numberOfLeadingZeros(); |
|
137 | 137 | |
138 | 138 | if (extension_loaded('decimal')) { |
139 | 139 | $decimalScale = max($internalScale*2, $this->numberOfTotalDigits()*2); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $answer = $adjustedNum; |
194 | 194 | |
195 | 195 | if ($exp2) { |
196 | - $answer = $answer->add(Numbers::makeNaturalLog2($internalScale + abs($exp2))->multiply($exp2)); |
|
196 | + $answer = $answer->add(Numbers::makeNaturalLog2($internalScale+abs($exp2))->multiply($exp2)); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | if ($exp1p1) { |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $baseValue = $this->trimmedScientificString($scale, $baseValue); |
124 | 124 | |
125 | 125 | if ($this->isNegative()) { |
126 | - $baseValue = '-' . $baseValue; |
|
126 | + $baseValue = '-'.$baseValue; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | if ($this->isImaginary()) { |
@@ -141,18 +141,18 @@ discard block |
||
141 | 141 | */ |
142 | 142 | private function trimmedScientificString(int $scale, string $baseValue): string |
143 | 143 | { |
144 | - if ($this->numberOfIntDigits() > $scale + 1) { |
|
145 | - $baseValue = substr($this->getWholePart(), 0, $scale + 1); |
|
144 | + if ($this->numberOfIntDigits() > $scale+1) { |
|
145 | + $baseValue = substr($this->getWholePart(), 0, $scale+1); |
|
146 | 146 | $baseValue = str_pad($baseValue, $this->numberOfIntDigits(), '0'); |
147 | - } elseif ($this->getWholePart() == '0' && $this->numberOfSigDecimalDigits() > $scale + 1) { |
|
147 | + } elseif ($this->getWholePart() == '0' && $this->numberOfSigDecimalDigits() > $scale+1) { |
|
148 | 148 | $baseValue = trim($this->getDecimalPart(), '0'); |
149 | - $baseValue = substr($baseValue, 0, $scale + 1); |
|
150 | - $baseValue = str_pad($baseValue, $this->numberOfLeadingZeros() + strlen($baseValue), '0', STR_PAD_LEFT); |
|
151 | - $baseValue = '0.' . $baseValue; |
|
152 | - } elseif ($this->numberOfTotalDigits() > $scale + 1) { |
|
149 | + $baseValue = substr($baseValue, 0, $scale+1); |
|
150 | + $baseValue = str_pad($baseValue, $this->numberOfLeadingZeros()+strlen($baseValue), '0', STR_PAD_LEFT); |
|
151 | + $baseValue = '0.'.$baseValue; |
|
152 | + } elseif ($this->numberOfTotalDigits() > $scale+1) { |
|
153 | 153 | $baseValue = $this->getWholePart() |
154 | 154 | . '.' |
155 | - . substr($this->getDecimalPart(), 0, ($scale + 1) - $this->numberOfIntDigits()); |
|
155 | + . substr($this->getDecimalPart(), 0, ($scale+1)-$this->numberOfIntDigits()); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return $baseValue; |
@@ -69,9 +69,9 @@ |
||
69 | 69 | $piDiv2 = M_PI_2; |
70 | 70 | |
71 | 71 | if ($thisNum < 0) { |
72 | - return -1 * ($piDiv2 - atan(abs($thisNum))); |
|
72 | + return -1*($piDiv2-atan(abs($thisNum))); |
|
73 | 73 | } else { |
74 | - return $piDiv2 - atan($thisNum); |
|
74 | + return $piDiv2-atan($thisNum); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | protected function helperArctanGCF(ImmutableDecimal $num, ?int $scale): ImmutableDecimal |
27 | 27 | { |
28 | 28 | $scale = $scale ?? $this->getScale(); |
29 | - $intScale = $scale + 2; |
|
30 | - $terms = $intScale + 2; |
|
29 | + $intScale = $scale+2; |
|
30 | + $terms = $intScale+2; |
|
31 | 31 | $x = new ImmutableDecimal($num, $intScale); |
32 | 32 | $aPart = new class($x) implements ContinuedFractionTermInterface { |
33 | 33 | private ImmutableDecimal $x; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | return Numbers::makeZero($this->intScale); |
76 | 76 | } |
77 | 77 | |
78 | - return SequenceProvider::nthOddNumber($n - 1); |
|
78 | + return SequenceProvider::nthOddNumber($n-1); |
|
79 | 79 | } |
80 | 80 | }; |
81 | 81 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $x2 = $x->pow(2); |
97 | 97 | $one = new ImmutableDecimal(1, $scale); |
98 | 98 | |
99 | - $aPart = new class($x2, $scale) implements ContinuedFractionTermInterface{ |
|
99 | + $aPart = new class($x2, $scale) implements ContinuedFractionTermInterface { |
|
100 | 100 | private ImmutableDecimal $x2; |
101 | 101 | private ImmutableDecimal $negTwo; |
102 | 102 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | }; |
126 | 126 | |
127 | - $bPart = new class() implements ContinuedFractionTermInterface{ |
|
127 | + $bPart = new class() implements ContinuedFractionTermInterface { |
|
128 | 128 | /** |
129 | 129 | * @param int $n |
130 | 130 | * @return ImmutableDecimal |