(string $left, string $right)
| 999 | } |
| 1000 | |
| 1001 | private function decimalAdd(string $left, string $right): string { |
| 1002 | [$leftSign, $leftDigits, $leftScale] = $this->decimalParts($left); |
| 1003 | [$rightSign, $rightDigits, $rightScale] = $this->decimalParts($right); |
| 1004 | $scale = max($leftScale, $rightScale); |
| 1005 | $leftDigits .= str_repeat('0', $scale - $leftScale); |
| 1006 | $rightDigits .= str_repeat('0', $scale - $rightScale); |
| 1007 | if ($leftSign === $rightSign) { |
| 1008 | $digits = $this->unsignedAdd($leftDigits, $rightDigits); |
| 1009 | $sign = $leftSign; |
| 1010 | } else { |
| 1011 | $comparison = $this->unsignedCompare($leftDigits, $rightDigits); |
| 1012 | if ($comparison === 0) { |
| 1013 | return '0'; |
| 1014 | } |
| 1015 | [$larger, $smaller, $sign] = $comparison > 0 |
| 1016 | ? [$leftDigits, $rightDigits, $leftSign] |
| 1017 | : [$rightDigits, $leftDigits, $rightSign]; |
| 1018 | $digits = $this->unsignedSubtract($larger, $smaller); |
| 1019 | } |
| 1020 | return $this->formatDecimal($sign, $digits, $scale); |
| 1021 | } |
| 1022 | |
| 1023 | private function decimalCompare(string $left, string $right): int { |
| 1024 | [$leftSign, $leftDigits, $leftScale] = $this->decimalParts($left); |
no test coverage detected