@@ -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) { |
@@ -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( $modScale + 2); |
|
91 | + $twoPi = Numbers::make2Pi($modScale+2); |
|
92 | + $pi = Numbers::makePi($modScale+2); |
|
93 | 93 | $piDivTwo = $pi->divide(2); |
94 | 94 | |
95 | 95 | if ($twoPi->truncate($scale)->isEqual($thisNum->truncate($scale))) { |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | |
114 | 114 | $answer = SeriesProvider::maclaurinSeries( |
115 | 115 | $modulo, |
116 | - function ($n) use ($negOne, $one) { |
|
116 | + function($n) use ($negOne, $one) { |
|
117 | 117 | |
118 | - return $n % 2 ? $negOne : $one; |
|
118 | + return $n%2 ? $negOne : $one; |
|
119 | 119 | }, |
120 | - function ($n) use ($intScale) { |
|
120 | + function($n) use ($intScale) { |
|
121 | 121 | return SequenceProvider::nthEvenNumber($n, $intScale); |
122 | 122 | }, |
123 | - function ($n) use ($intScale) { |
|
123 | + function($n) use ($intScale) { |
|
124 | 124 | return SequenceProvider::nthEvenNumber($n, $intScale)->factorial(); |
125 | 125 | }, |
126 | 126 | 0, |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | protected function tanScale(int $scale = null): string |
140 | 140 | { |
141 | 141 | $scale = $scale ?? $this->getScale(); |
142 | - $intScale = $scale + 4; |
|
142 | + $intScale = $scale+4; |
|
143 | 143 | $intScale = $intScale+$this->numberOfIntDigits()+$this->numberOfLeadingZeros(); |
144 | 144 | |
145 | 145 | $thisNum = Numbers::make(Numbers::IMMUTABLE, $this->getValue(NumberBase::Ten), $intScale); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | |
287 | 287 | if ($mod2Pi->isEqual(0)) { |
288 | 288 | return static::INFINITY; |
289 | - } elseif($modPi->isEqual(0)) { |
|
289 | + } elseif ($modPi->isEqual(0)) { |
|
290 | 290 | return static::NEG_INFINITY; |
291 | 291 | } |
292 | 292 |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $total = strlen($fractional); |
148 | 148 | $fractional = ltrim($fractional, '0'); |
149 | 149 | |
150 | - return ($total - strlen($fractional)); |
|
150 | + return ($total-strlen($fractional)); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function numberOfTotalDigits(): int |
159 | 159 | { |
160 | - return $this->numberOfDecimalDigits() + $this->numberOfIntDigits(); |
|
160 | + return $this->numberOfDecimalDigits()+$this->numberOfIntDigits(); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | if ($exp > 0) { |
107 | 107 | $exp -= strlen($right); |
108 | 108 | if ($exp >= 0) { |
109 | - $right = str_pad($right, $exp - 1, '0').'.0'; |
|
109 | + $right = str_pad($right, $exp-1, '0').'.0'; |
|
110 | 110 | } else { |
111 | - $right = substr($right, 0, strlen($right) + abs($exp)).'.'.substr($right, strlen($right) + abs($exp) + 1); |
|
111 | + $right = substr($right, 0, strlen($right)+abs($exp)).'.'.substr($right, strlen($right)+abs($exp)+1); |
|
112 | 112 | } |
113 | 113 | } else { |
114 | 114 | $exp += strlen($left); |
115 | 115 | if ($exp >= 0) { |
116 | - $left = substr($left, 0, $exp).'.'.substr($left, $exp + 1); |
|
116 | + $left = substr($left, 0, $exp).'.'.substr($left, $exp+1); |
|
117 | 117 | } else { |
118 | 118 | $left = '0.'.str_pad($left, abs($exp)+1, '0', STR_PAD_LEFT); |
119 | 119 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @param NumberBase $base |
259 | 259 | * @return DecimalInterface|NumberInterface |
260 | 260 | */ |
261 | - public function setBase(NumberBase $base): DecimalInterface|NumberInterface |
|
261 | + public function setBase(NumberBase $base): DecimalInterface | NumberInterface |
|
262 | 262 | { |
263 | 263 | $this->base = $base; |
264 | 264 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * |
271 | 271 | * @return DecimalInterface|NumberInterface |
272 | 272 | */ |
273 | - public function abs(): DecimalInterface|NumberInterface |
|
273 | + public function abs(): DecimalInterface | NumberInterface |
|
274 | 274 | { |
275 | 275 | $newValue = $this->absValue(); |
276 | 276 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @param DecimalInterface $num |
282 | 282 | * @return float|int |
283 | 283 | */ |
284 | - protected static function translateToNative(DecimalInterface $num): float|int |
|
284 | + protected static function translateToNative(DecimalInterface $num): float | int |
|
285 | 285 | { |
286 | 286 | return ($num->isInt() ? $num->asInt() : $num->asFloat()); |
287 | 287 | } |
@@ -334,13 +334,13 @@ discard block |
||
334 | 334 | * @param bool $setToNewBase |
335 | 335 | * @return DecimalInterface |
336 | 336 | */ |
337 | - abstract protected function setValue(string $value, ?int $scale = null, ?NumberBase $base = null, bool $setToNewBase = false): DecimalInterface; // TODO: Check usages for base correctness & preservation |
|
337 | + abstract protected function setValue(string $value, ?int $scale = null, ?NumberBase $base = null, bool $setToNewBase = false): DecimalInterface;// TODO: Check usages for base correctness & preservation |
|
338 | 338 | |
339 | 339 | /** |
340 | 340 | * @param NumberInterface|string|int|float $mod |
341 | 341 | * @return DecimalInterface |
342 | 342 | */ |
343 | - abstract public function continuousModulo(NumberInterface|string|int|float $mod): DecimalInterface; |
|
343 | + abstract public function continuousModulo(NumberInterface | string | int | float $mod): DecimalInterface; |
|
344 | 344 | |
345 | 345 | /** |
346 | 346 | * @param string $decimalPart |
@@ -106,7 +106,7 @@ |
||
106 | 106 | while ($runningTotal->isGreaterThan(0)) { |
107 | 107 | $current = gmp_div_qr($runningTotal->getAsBaseTenRealNumber(), $baseNum->getAsBaseTenRealNumber()); |
108 | 108 | $mod = (int)$current[1]; |
109 | - $stringVal = self::$chars[$mod] . $stringVal; |
|
109 | + $stringVal = self::$chars[$mod].$stringVal; |
|
110 | 110 | $runningTotal = Numbers::make(Numbers::IMMUTABLE, $current[0]); |
111 | 111 | } |
112 | 112 | } else { |
@@ -26,7 +26,7 @@ |
||
26 | 26 | $remainder = substr($remainder, 0, 3); |
27 | 27 | $target = (int)($digit.$remainder); |
28 | 28 | $rangeMin = 0; |
29 | - $rangeMax = (int)str_repeat('9', strlen($remainder) + 1); |
|
29 | + $rangeMax = (int)str_repeat('9', strlen($remainder)+1); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $random = RandomProvider::randomInt($rangeMin, $rangeMax, RandomMode::Speed)->asInt(); |
@@ -17,7 +17,7 @@ |
||
17 | 17 | $remainder = $this->remainderCheck(); |
18 | 18 | |
19 | 19 | if ($early == 0) { |
20 | - return ($nextDigit % 2 == 1 && !$remainder) ? 0 : 1; |
|
20 | + return ($nextDigit%2 == 1 && !$remainder) ? 0 : 1; |
|
21 | 21 | } else { |
22 | 22 | return $early == 1 ? 1 : 0; |
23 | 23 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | $remainder = $this->remainderCheck(); |
18 | 18 | |
19 | 19 | if ($early == 0) { |
20 | - return ($nextDigit % 2 == 0 && !$remainder) ? 0 : 1; |
|
20 | + return ($nextDigit%2 == 0 && !$remainder) ? 0 : 1; |
|
21 | 21 | } else { |
22 | 22 | return $early == 1 ? 1 : 0; |
23 | 23 | } |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | * @throws IncompatibleObjectState |
31 | 31 | */ |
32 | 32 | public static function randomInt( |
33 | - int|string|DecimalInterface $min, |
|
34 | - int|string|DecimalInterface $max, |
|
33 | + int | string | DecimalInterface $min, |
|
34 | + int | string | DecimalInterface $max, |
|
35 | 35 | RandomMode $mode = RandomMode::Entropy |
36 | 36 | ): ImmutableDecimal |
37 | 37 | { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | throw new OptionalExit( |
108 | 108 | 'System error from random_bytes().', |
109 | 109 | 'Ensure your system is configured correctly.', |
110 | - 'A call to random_bytes() threw a system level exception. Most often this is due to a problem with entropy sources in your configuration. Original exception message: ' . $e->getMessage() |
|
110 | + 'A call to random_bytes() threw a system level exception. Most often this is due to a problem with entropy sources in your configuration. Original exception message: '.$e->getMessage() |
|
111 | 111 | ); |
112 | 112 | } |
113 | 113 | } elseif ($mode == RandomMode::Speed) { |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | */ |
148 | 148 | $entropyBytes = random_bytes($bytesNeeded->asInt()); |
149 | 149 | $baseTwoBytes = ''; |
150 | - for($i = 0; $i < strlen($entropyBytes); $i++){ |
|
151 | - $baseTwoBytes .= decbin( ord( $entropyBytes[$i] ) ); |
|
150 | + for ($i = 0;$i < strlen($entropyBytes);$i++) { |
|
151 | + $baseTwoBytes .= decbin(ord($entropyBytes[$i])); |
|
152 | 152 | } |
153 | 153 | } catch (Exception $e) { |
154 | 154 | throw new OptionalExit( |
155 | 155 | 'System error from random_bytes().', |
156 | 156 | 'Ensure your system is configured correctly.', |
157 | - 'A call to random_bytes() threw a system level exception. Most often this is due to a problem with entropy sources in your configuration. Original exception message: ' . $e->getMessage() |
|
157 | + 'A call to random_bytes() threw a system level exception. Most often this is due to a problem with entropy sources in your configuration. Original exception message: '.$e->getMessage() |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
@@ -243,8 +243,8 @@ discard block |
||
243 | 243 | * @throws IncompatibleObjectState |
244 | 244 | */ |
245 | 245 | public static function randomReal( |
246 | - int|string|DecimalInterface $min, |
|
247 | - int|string|DecimalInterface $max, |
|
246 | + int | string | DecimalInterface $min, |
|
247 | + int | string | DecimalInterface $max, |
|
248 | 248 | int $scale, |
249 | 249 | RandomMode $mode = RandomMode::Entropy |
250 | 250 | ): ImmutableDecimal |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * We cannot take advantage of a more efficient check for the top end of the range, so the |
370 | 370 | * less than check is all we need. |
371 | 371 | */ |
372 | - $maxDecimal = str_pad('1', $scale + 1, '0'); |
|
372 | + $maxDecimal = str_pad('1', $scale+1, '0'); |
|
373 | 373 | } else { |
374 | 374 | /** |
375 | 375 | * The max value is guaranteed to have a decimal portion here since we excluded max being |