@@ -4,7 +4,6 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace Tdn\PhpTypes\Math\Library; |
| 6 | 6 | |
| 7 | -use Tdn\PhpTypes\Exception\InvalidNumberException; |
|
| 8 | 7 | use Tdn\PhpTypes\Math\DefaultMathAdapter; |
| 9 | 8 | use Tdn\PhpTypes\Type\StringType; |
| 10 | 9 | |
@@ -37,8 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function add(string $leftOperand, string $rightOperand, int $precision = 0) : string |
| 39 | 39 | { |
| 40 | - return (string)($this->isIntOperation($precision) ? (intval($leftOperand) + intval($rightOperand)) : |
|
| 41 | - round(floatval($leftOperand) + floatval($rightOperand), $precision, $this->roundingStrategy)); |
|
| 40 | + return (string) ($this->isIntOperation($precision) ? (intval($leftOperand) + intval($rightOperand)) : round(floatval($leftOperand) + floatval($rightOperand), $precision, $this->roundingStrategy)); |
|
| 42 | 41 | } |
| 43 | 42 | |
| 44 | 43 | /** |
@@ -52,8 +51,7 @@ discard block |
||
| 52 | 51 | */ |
| 53 | 52 | public function subtract(string $leftOperand, string $rightOperand, int $precision = 0) : string |
| 54 | 53 | { |
| 55 | - return (string)($this->isIntOperation($precision) ? (intval($leftOperand) - intval($rightOperand)) : |
|
| 56 | - round($leftOperand - $rightOperand, $precision, $this->roundingStrategy)); |
|
| 54 | + return (string) ($this->isIntOperation($precision) ? (intval($leftOperand) - intval($rightOperand)) : round($leftOperand - $rightOperand, $precision, $this->roundingStrategy)); |
|
| 57 | 55 | } |
| 58 | 56 | |
| 59 | 57 | /** |
@@ -67,8 +65,7 @@ discard block |
||
| 67 | 65 | */ |
| 68 | 66 | public function multiply(string $leftOperand, string $rightOperand, int $precision = 0) : string |
| 69 | 67 | { |
| 70 | - return (string)($this->isIntOperation($precision) ? (intval($leftOperand) * intval($rightOperand)) : |
|
| 71 | - round($leftOperand * $rightOperand, ($precision ?? 0), $this->roundingStrategy)); |
|
| 68 | + return (string) ($this->isIntOperation($precision) ? (intval($leftOperand) * intval($rightOperand)) : round($leftOperand * $rightOperand, ($precision ?? 0), $this->roundingStrategy)); |
|
| 72 | 69 | } |
| 73 | 70 | |
| 74 | 71 | /** |
@@ -82,8 +79,7 @@ discard block |
||
| 82 | 79 | */ |
| 83 | 80 | public function divide(string $leftOperand, string $rightOperand, int $precision = 0) : string |
| 84 | 81 | { |
| 85 | - return (string)($this->isIntOperation($precision) ? (intval($leftOperand) / intval($rightOperand)) : |
|
| 86 | - round($leftOperand / $rightOperand, $precision, $this->roundingStrategy)); |
|
| 82 | + return (string) ($this->isIntOperation($precision) ? (intval($leftOperand) / intval($rightOperand)) : round($leftOperand / $rightOperand, $precision, $this->roundingStrategy)); |
|
| 87 | 83 | } |
| 88 | 84 | |
| 89 | 85 | /** |
@@ -111,7 +107,7 @@ discard block |
||
| 111 | 107 | */ |
| 112 | 108 | public function modulus(string $operand, string $modulus, int $precision = 0) : string |
| 113 | 109 | { |
| 114 | - return (string)round( |
|
| 110 | + return (string) round( |
|
| 115 | 111 | fmod( |
| 116 | 112 | floatval($operand), |
| 117 | 113 | floatval($modulus) |
@@ -132,7 +128,7 @@ discard block |
||
| 132 | 128 | */ |
| 133 | 129 | public function power(string $leftOperand, string $rightOperand, int $precision = 0) : string |
| 134 | 130 | { |
| 135 | - return (string)round( |
|
| 131 | + return (string) round( |
|
| 136 | 132 | pow( |
| 137 | 133 | floatval($leftOperand), |
| 138 | 134 | floatval($rightOperand) |
@@ -152,7 +148,7 @@ discard block |
||
| 152 | 148 | */ |
| 153 | 149 | public function squareRoot(string $operand, int $precision = 0) : string |
| 154 | 150 | { |
| 155 | - return (string)round(sqrt(floatval($operand)), ($precision ?? 0), $this->roundingStrategy); |
|
| 151 | + return (string) round(sqrt(floatval($operand)), ($precision ?? 0), $this->roundingStrategy); |
|
| 156 | 152 | } |
| 157 | 153 | |
| 158 | 154 | /** |
@@ -164,7 +160,7 @@ discard block |
||
| 164 | 160 | */ |
| 165 | 161 | public function absolute(string $operand) : string |
| 166 | 162 | { |
| 167 | - return (string)abs($operand); |
|
| 163 | + return (string) abs($operand); |
|
| 168 | 164 | } |
| 169 | 165 | |
| 170 | 166 | /** |
@@ -193,7 +189,7 @@ discard block |
||
| 193 | 189 | return $this->gamma((string) $operand); |
| 194 | 190 | } |
| 195 | 191 | |
| 196 | - $factorial = function (string $num) use (&$factorial) { |
|
| 192 | + $factorial = function(string $num) use (&$factorial) { |
|
| 197 | 193 | if ($num < 2) { |
| 198 | 194 | return 1; |
| 199 | 195 | } |
@@ -201,7 +197,7 @@ discard block |
||
| 201 | 197 | return $factorial(strval($num - 1)) * $num; |
| 202 | 198 | }; |
| 203 | 199 | |
| 204 | - return (string)$factorial($operand); |
|
| 200 | + return (string) $factorial($operand); |
|
| 205 | 201 | } |
| 206 | 202 | |
| 207 | 203 | /** |
@@ -214,13 +210,13 @@ discard block |
||
| 214 | 210 | */ |
| 215 | 211 | public function gcd(string $leftOperand, string $rightOperand) : string |
| 216 | 212 | { |
| 217 | - $gcd = function (string $a, string $b) use (&$gcd) { |
|
| 213 | + $gcd = function(string $a, string $b) use (&$gcd) { |
|
| 218 | 214 | return $b ? $gcd($b, strval($a % $b)) : $a; |
| 219 | 215 | }; |
| 220 | 216 | |
| 221 | 217 | $exponent = $this->getSmallestDecimalPlaceCount($leftOperand, $rightOperand); |
| 222 | 218 | |
| 223 | - return (string)( |
|
| 219 | + return (string) ( |
|
| 224 | 220 | $gcd( |
| 225 | 221 | strval($leftOperand * (pow(10, $exponent))), |
| 226 | 222 | strval($rightOperand * (pow(10, $exponent))) |
@@ -258,7 +254,7 @@ discard block |
||
| 258 | 254 | } |
| 259 | 255 | } |
| 260 | 256 | |
| 261 | - return (string)$i; |
|
| 257 | + return (string) $i; |
|
| 262 | 258 | } |
| 263 | 259 | |
| 264 | 260 | /** |
@@ -349,7 +345,7 @@ discard block |
||
| 349 | 345 | if ($arg_was_less_than_one) { |
| 350 | 346 | $y += 1.0; |
| 351 | 347 | } else { |
| 352 | - $n = floor($y) - 1; # will use n later |
|
| 348 | + $n = floor($y) - 1; # will use n later |
|
| 353 | 349 | $y -= $n; |
| 354 | 350 | } |
| 355 | 351 | |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | */ |
| 135 | 135 | protected function getOperationType(string $a, string $b = null) : string |
| 136 | 136 | { |
| 137 | - $getType = function ($v, $previousType = null) { |
|
| 137 | + $getType = function($v, $previousType = null) { |
|
| 138 | 138 | $previousType = $previousType ?? self::TYPE_INT; |
| 139 | 139 | |
| 140 | 140 | return (strpos($v, '.') !== false) ? self::TYPE_FLOAT : $previousType; |