MCPcopy Create free account
hub / github.com/Rello/analytics / decimalAdd

Method decimalAdd

lib/Service/FlexibleStorageService.php:1001–1021  ·  view source on GitHub ↗
(string $left, string $right)

Source from the content-addressed store, hash-verified

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);

Callers 2

applyTimeAggregationMethod · 0.95
applyTopNMethod · 0.95

Calls 5

decimalPartsMethod · 0.95
unsignedAddMethod · 0.95
unsignedCompareMethod · 0.95
unsignedSubtractMethod · 0.95
formatDecimalMethod · 0.95

Tested by

no test coverage detected