@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function sort(): NumberCollectionInterface |
| 162 | 162 | { |
| 163 | - $this->getCollection()->sort(function($left, $right){ |
|
| 163 | + $this->getCollection()->sort(function($left, $right) { |
|
| 164 | 164 | return ArithmeticProvider::compare($left->getAsBaseTenRealNumber(), $right->getAsBaseTenRealNumber()); |
| 165 | 165 | }); |
| 166 | 166 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | public function getRandom(): NumberInterface |
| 295 | 295 | { |
| 296 | - $maxKey = $this->getCollection()->count() - 1; |
|
| 296 | + $maxKey = $this->getCollection()->count()-1; |
|
| 297 | 297 | |
| 298 | 298 | $key = RandomProvider::randomInt(0, $maxKey, RandomProvider::MODE_SPEED)->asInt(); |
| 299 | 299 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $roundedPartString = $currentPart ? $decimalPart : $wholePart; |
| 80 | 80 | $otherPart = $currentPart ? str_split($wholePart) : str_split($decimalPart); |
| 81 | 81 | $baseLength = $currentPart ? strlen($decimalPart)-1 : strlen($wholePart); |
| 82 | - $pos = $currentPart ? $places : $baseLength + $places; |
|
| 82 | + $pos = $currentPart ? $places : $baseLength+$places; |
|
| 83 | 83 | $carry = 0; |
| 84 | 84 | |
| 85 | 85 | if ($currentPart) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | break; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $digit = (int)$roundedPart[$pos] + $carry; |
|
| 96 | + $digit = (int) $roundedPart[$pos]+$carry; |
|
| 97 | 97 | |
| 98 | 98 | if ($carry == 0 && $digit == 5) { |
| 99 | 99 | static::$remainder = substr($roundedPartString, $pos+1); |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | if ($pos == 0) { |
| 105 | 105 | if ($currentPart) { |
| 106 | - $nextDigit = (int)$otherPart[count($otherPart)-1]; |
|
| 106 | + $nextDigit = (int) $otherPart[count($otherPart)-1]; |
|
| 107 | 107 | } else { |
| 108 | 108 | $nextDigit = 0; |
| 109 | 109 | } |
| 110 | 110 | } else { |
| 111 | - $nextDigit = (int)$roundedPart[$pos-1]; |
|
| 111 | + $nextDigit = (int) $roundedPart[$pos-1]; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | if ($carry == 0) { |
| 115 | - $carry = match (self::getRoundingMode()) { |
|
| 115 | + $carry = match(self::getRoundingMode()) { |
|
| 116 | 116 | self::MODE_HALF_UP => self::roundHalfUp($digit), |
| 117 | 117 | self::MODE_HALF_DOWN => self::roundHalfDown($digit), |
| 118 | 118 | self::MODE_HALF_ODD => self::roundHalfOdd($digit, $nextDigit), |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | $remainder = self::remainderCheck(); |
| 240 | 240 | |
| 241 | 241 | if ($early == 0) { |
| 242 | - return ($nextDigit % 2 == 0 && !$remainder) ? 0 : 1; |
|
| 242 | + return ($nextDigit%2 == 0 && !$remainder) ? 0 : 1; |
|
| 243 | 243 | } else { |
| 244 | 244 | return $early == 1 ? 1 : 0; |
| 245 | 245 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | $remainder = self::remainderCheck(); |
| 252 | 252 | |
| 253 | 253 | if ($early == 0) { |
| 254 | - return ($nextDigit % 2 == 1 && !$remainder) ? 0 : 1; |
|
| 254 | + return ($nextDigit%2 == 1 && !$remainder) ? 0 : 1; |
|
| 255 | 255 | } else { |
| 256 | 256 | return $early == 1 ? 1 : 0; |
| 257 | 257 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | if ($early == 0 && !$remainder) { |
| 303 | 303 | $val = self::$alt; |
| 304 | - self::$alt = (int)!$val; |
|
| 304 | + self::$alt = (int) !$val; |
|
| 305 | 305 | |
| 306 | 306 | return $val; |
| 307 | 307 | } else { |
@@ -319,9 +319,9 @@ discard block |
||
| 319 | 319 | $rangeMax = 9; |
| 320 | 320 | } else { |
| 321 | 321 | $remainder = substr($remainder, 0, 3); |
| 322 | - $target = (int)($digit.$remainder); |
|
| 322 | + $target = (int) ($digit.$remainder); |
|
| 323 | 323 | $rangeMin = 0; |
| 324 | - $rangeMax = (int)str_repeat('9', strlen($remainder) + 1); |
|
| 324 | + $rangeMax = (int) str_repeat('9', strlen($remainder)+1); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | $random = RandomProvider::randomInt($rangeMin, $rangeMax, RandomProvider::MODE_SPEED)->asInt(); |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @throws IncompatibleObjectState |
| 29 | 29 | */ |
| 30 | 30 | public static function randomInt( |
| 31 | - int|string|DecimalInterface $min, |
|
| 32 | - int|string|DecimalInterface $max, |
|
| 31 | + int | string | DecimalInterface $min, |
|
| 32 | + int | string | DecimalInterface $max, |
|
| 33 | 33 | #[ExpectedValues([self::MODE_ENTROPY, self::MODE_SPEED])] |
| 34 | 34 | int $mode = self::MODE_ENTROPY |
| 35 | 35 | ): ImmutableDecimal |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | throw new OptionalExit( |
| 107 | 107 | 'System error from random_bytes().', |
| 108 | 108 | 'Ensure your system is configured correctly.', |
| 109 | - '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() |
|
| 109 | + '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 | 110 | ); |
| 111 | 111 | } |
| 112 | 112 | } elseif ($mode == self::MODE_SPEED) { |
@@ -148,14 +148,14 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | $entropyBytes = random_bytes($bytesNeeded->asInt()); |
| 150 | 150 | $baseTwoBytes = ''; |
| 151 | - for($i = 0; $i < strlen($entropyBytes); $i++){ |
|
| 152 | - $baseTwoBytes .= decbin( ord( $entropyBytes[$i] ) ); |
|
| 151 | + for ($i = 0; $i < strlen($entropyBytes); $i++) { |
|
| 152 | + $baseTwoBytes .= decbin(ord($entropyBytes[$i])); |
|
| 153 | 153 | } |
| 154 | 154 | } catch (Exception $e) { |
| 155 | 155 | throw new OptionalExit( |
| 156 | 156 | 'System error from random_bytes().', |
| 157 | 157 | 'Ensure your system is configured correctly.', |
| 158 | - '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 | + '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() |
|
| 159 | 159 | ); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -250,8 +250,8 @@ discard block |
||
| 250 | 250 | * @throws IncompatibleObjectState |
| 251 | 251 | */ |
| 252 | 252 | public static function randomReal( |
| 253 | - int|string|DecimalInterface $min, |
|
| 254 | - int|string|DecimalInterface $max, |
|
| 253 | + int | string | DecimalInterface $min, |
|
| 254 | + int | string | DecimalInterface $max, |
|
| 255 | 255 | int $scale, |
| 256 | 256 | #[ExpectedValues([self::MODE_ENTROPY, self::MODE_SPEED])] |
| 257 | 257 | int $mode = self::MODE_ENTROPY |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * First we use string manipulation to extract the decimal portion as an integer value, the we right |
| 369 | 369 | * pad with zeroes to make sure that the entire scale is part of the valid result set. |
| 370 | 370 | */ |
| 371 | - $minDecimal = substr($min->getValue(), strpos($min->getValue(), '.') + 1); |
|
| 371 | + $minDecimal = substr($min->getValue(), strpos($min->getValue(), '.')+1); |
|
| 372 | 372 | $minDecimal = str_pad($minDecimal, $scale, '0', STR_PAD_RIGHT); |
| 373 | 373 | } |
| 374 | 374 | |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * We cannot take advantage of a more efficient check for the top end of the range, so the |
| 378 | 378 | * less than check is all we need. |
| 379 | 379 | */ |
| 380 | - $maxDecimal = str_pad('1', $scale + 1, '0', STR_PAD_RIGHT); |
|
| 380 | + $maxDecimal = str_pad('1', $scale+1, '0', STR_PAD_RIGHT); |
|
| 381 | 381 | } else { |
| 382 | 382 | /** |
| 383 | 383 | * The max value is guaranteed to have a decimal portion here since we excluded max being |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | private string $left; |
| 14 | 14 | private string $right; |
| 15 | 15 | |
| 16 | - public function __construct(NumberInterface|ComponentInterface $left, NumberInterface|ComponentInterface $right) |
|
| 16 | + public function __construct(NumberInterface | ComponentInterface $left, NumberInterface | ComponentInterface $right) |
|
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | $this->left = ($left instanceof NumberInterface ? $left->getValue() : $left->getOutput()); |
@@ -14,57 +14,57 @@ discard block |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | const EULER_ZIGZAG = [ |
| 17 | - '1', // 0 |
|
| 18 | - '1', // 1 |
|
| 19 | - '1', // 2 |
|
| 20 | - '2', // 3 |
|
| 21 | - '5', // 4 |
|
| 22 | - '16', // 5 |
|
| 23 | - '61', // 6 |
|
| 24 | - '272', // 7 |
|
| 25 | - '1385', // 8 |
|
| 26 | - '7936', // 9 |
|
| 27 | - '50521', // 10 |
|
| 28 | - '353792', // 11 |
|
| 29 | - '2702765', // 12 |
|
| 30 | - '22368256', // 13 |
|
| 31 | - '199360981', // 14 |
|
| 32 | - '1903757312', // 15 |
|
| 33 | - '19391512145', // 16 |
|
| 34 | - '209865342976', // 17 |
|
| 35 | - '2404879675441', // 18 |
|
| 36 | - '29088885112832', // 19 |
|
| 37 | - '370371188237525', // 20 |
|
| 38 | - '4951498053124096', // 21 |
|
| 39 | - '69348874393137901', // 22 |
|
| 40 | - '1015423886506852352', // 23 |
|
| 41 | - '15514534163557086905', // 24 |
|
| 42 | - '246921480190207983616', // 25 |
|
| 43 | - '4087072509293123892361', // 26 |
|
| 44 | - '70251601603943959887872', // 27 |
|
| 45 | - '1252259641403629865468285', // 28 |
|
| 46 | - '23119184187809597841473536', // 29 |
|
| 47 | - '441543893249023104553682821', // 30 |
|
| 48 | - '8713962757125169296170811392', // 31 |
|
| 49 | - '177519391579539289436664789665', // 32 |
|
| 50 | - '3729407703720529571097509625856', // 33 |
|
| 51 | - '80723299235887898062168247453281', // 34 |
|
| 52 | - '1798651693450888780071750349094912', // 35 |
|
| 53 | - '41222060339517702122347079671259045', // 36 |
|
| 54 | - '970982810785059112379399707952152576', // 37 |
|
| 55 | - '23489580527043108252017828576198947741', // 38 |
|
| 56 | - '583203324917310043943191641625494290432', // 39 |
|
| 57 | - '14851150718114980017877156781405826684425', // 40 |
|
| 58 | - '387635983772083031828014624002175135645696', // 41 |
|
| 59 | - '10364622733519612119397957304745185976310201', // 42 |
|
| 60 | - '283727921907431909304183316295787837183229952', // 43 |
|
| 61 | - '7947579422597592703608040510088070619519273805', // 44 |
|
| 62 | - '227681379129930886488600284336316164603920777216', // 45 |
|
| 63 | - '6667537516685544977435028474773748197524107684661', // 46 |
|
| 64 | - '199500252157859031027160499643195658166340757225472', // 47 |
|
| 65 | - '6096278645568542158691685742876843153976539044435185', // 48 |
|
| 66 | - '190169564657928428175235445073924928592047775873499136', // 49 |
|
| 67 | - '6053285248188621896314383785111649088103498225146815121', // 50 |
|
| 17 | + '1', // 0 |
|
| 18 | + '1', // 1 |
|
| 19 | + '1', // 2 |
|
| 20 | + '2', // 3 |
|
| 21 | + '5', // 4 |
|
| 22 | + '16', // 5 |
|
| 23 | + '61', // 6 |
|
| 24 | + '272', // 7 |
|
| 25 | + '1385', // 8 |
|
| 26 | + '7936', // 9 |
|
| 27 | + '50521', // 10 |
|
| 28 | + '353792', // 11 |
|
| 29 | + '2702765', // 12 |
|
| 30 | + '22368256', // 13 |
|
| 31 | + '199360981', // 14 |
|
| 32 | + '1903757312', // 15 |
|
| 33 | + '19391512145', // 16 |
|
| 34 | + '209865342976', // 17 |
|
| 35 | + '2404879675441', // 18 |
|
| 36 | + '29088885112832', // 19 |
|
| 37 | + '370371188237525', // 20 |
|
| 38 | + '4951498053124096', // 21 |
|
| 39 | + '69348874393137901', // 22 |
|
| 40 | + '1015423886506852352', // 23 |
|
| 41 | + '15514534163557086905', // 24 |
|
| 42 | + '246921480190207983616', // 25 |
|
| 43 | + '4087072509293123892361', // 26 |
|
| 44 | + '70251601603943959887872', // 27 |
|
| 45 | + '1252259641403629865468285', // 28 |
|
| 46 | + '23119184187809597841473536', // 29 |
|
| 47 | + '441543893249023104553682821', // 30 |
|
| 48 | + '8713962757125169296170811392', // 31 |
|
| 49 | + '177519391579539289436664789665', // 32 |
|
| 50 | + '3729407703720529571097509625856', // 33 |
|
| 51 | + '80723299235887898062168247453281', // 34 |
|
| 52 | + '1798651693450888780071750349094912', // 35 |
|
| 53 | + '41222060339517702122347079671259045', // 36 |
|
| 54 | + '970982810785059112379399707952152576', // 37 |
|
| 55 | + '23489580527043108252017828576198947741', // 38 |
|
| 56 | + '583203324917310043943191641625494290432', // 39 |
|
| 57 | + '14851150718114980017877156781405826684425', // 40 |
|
| 58 | + '387635983772083031828014624002175135645696', // 41 |
|
| 59 | + '10364622733519612119397957304745185976310201', // 42 |
|
| 60 | + '283727921907431909304183316295787837183229952', // 43 |
|
| 61 | + '7947579422597592703608040510088070619519273805', // 44 |
|
| 62 | + '227681379129930886488600284336316164603920777216', // 45 |
|
| 63 | + '6667537516685544977435028474773748197524107684661', // 46 |
|
| 64 | + '199500252157859031027160499643195658166340757225472', // 47 |
|
| 65 | + '6096278645568542158691685742876843153976539044435185', // 48 |
|
| 66 | + '190169564657928428175235445073924928592047775873499136', // 49 |
|
| 67 | + '6053285248188621896314383785111649088103498225146815121', // 50 |
|
| 68 | 68 | ]; |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | if ($asCollection) { |
| 83 | 83 | $sequence = new NumberCollection(); |
| 84 | 84 | |
| 85 | - for ($i = 0;$i < $collectionSize;$i++) { |
|
| 86 | - $sequence->push(self::nthOddNumber($n + $i)); |
|
| 85 | + for ($i = 0; $i < $collectionSize; $i++) { |
|
| 86 | + $sequence->push(self::nthOddNumber($n+$i)); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | return $sequence; |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | if ($asCollection) { |
| 116 | 116 | $sequence = new NumberCollection(); |
| 117 | 117 | |
| 118 | - for ($i = 0;$i < $collectionSize;$i++) { |
|
| 119 | - $sequence->push(self::nthEvenNumber($n + $i)); |
|
| 118 | + for ($i = 0; $i < $collectionSize; $i++) { |
|
| 119 | + $sequence->push(self::nthEvenNumber($n+$i)); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | return $sequence; |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | if ($asCollection) { |
| 148 | 148 | $sequence = new NumberCollection(); |
| 149 | 149 | |
| 150 | - for ($i = 0;$i < $collectionSize;$i++) { |
|
| 151 | - $sequence->push(self::nthPowerNegativeOne($n + $i)); |
|
| 150 | + for ($i = 0; $i < $collectionSize; $i++) { |
|
| 151 | + $sequence->push(self::nthPowerNegativeOne($n+$i)); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return $sequence; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - return ($n % 2 ? new ImmutableDecimal(-1) : new ImmutableDecimal(1)); |
|
| 157 | + return ($n%2 ? new ImmutableDecimal(-1) : new ImmutableDecimal(1)); |
|
| 158 | 158 | |
| 159 | 159 | } |
| 160 | 160 | |
@@ -174,8 +174,8 @@ discard block |
||
| 174 | 174 | if ($asCollection) { |
| 175 | 175 | $sequence = new NumberCollection(); |
| 176 | 176 | |
| 177 | - for ($i = 0;$i < $collectionSize;$i++) { |
|
| 178 | - $sequence->push(self::nthEulerZigzag($n + $i)); |
|
| 177 | + for ($i = 0; $i < $collectionSize; $i++) { |
|
| 178 | + $sequence->push(self::nthEulerZigzag($n+$i)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | return $sequence; |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $sequence = new NumberCollection(); |
| 263 | 263 | $sequence->push($fastFib[0]); |
| 264 | 264 | $sequence->push($fastFib[1]); |
| 265 | - for ($i = 0;$i < ($collectionSize-2);$i++) { |
|
| 265 | + for ($i = 0; $i < ($collectionSize-2); $i++) { |
|
| 266 | 266 | $sequence->push($sequence->get($i)->add($sequence[$i+1])); |
| 267 | 267 | } |
| 268 | 268 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $total = strlen($fractional); |
| 106 | 106 | $fractional = ltrim($fractional, '0'); |
| 107 | 107 | |
| 108 | - return ($total - strlen($fractional)); |
|
| 108 | + return ($total-strlen($fractional)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | public function isFloat(): bool |
| 182 | 182 | { |
| 183 | 183 | |
| 184 | - return (bool)ArithmeticProvider::compare($this->getDecimalPart(), '0'); |
|
| 184 | + return (bool) ArithmeticProvider::compare($this->getDecimalPart(), '0'); |
|
| 185 | 185 | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public function asFloat(): float |
| 189 | 189 | { |
| 190 | - return (float)$this->asReal(); |
|
| 190 | + return (float) $this->asReal(); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | protected function reduceDecimals(array $decimalArray, $pos, $add) |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | $abs = $this instanceof ImmutableDecimal ? $this->abs() : new ImmutableDecimal($this->absValue()); |
| 23 | 23 | $x = $this instanceof ImmutableDecimal ? $this : new ImmutableDecimal($this->getValue()); |
| 24 | 24 | $x2 = $x->pow(2); |
| 25 | - $intScale = $scale + $abs->asInt(); |
|
| 25 | + $intScale = $scale+$abs->asInt(); |
|
| 26 | 26 | |
| 27 | 27 | $one = new ImmutableDecimal(1); |
| 28 | 28 | $two = new ImmutableDecimal(2); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $prevDenom = new ImmutableDecimal(0); |
| 31 | 31 | |
| 32 | 32 | for ($i = $intScale; $i >= 0; $i--) { |
| 33 | - $thisDenom = $six->add(4 * $i)->add($prevDenom); |
|
| 33 | + $thisDenom = $six->add(4*$i)->add($prevDenom); |
|
| 34 | 34 | $prevDenom = $x2->divide($thisDenom, $intScale); |
| 35 | 35 | } |
| 36 | 36 | $value = $one->add($x->multiply(2)->divide($two->subtract($x)->add($prevDenom), $intScale)); |