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

Method decimalAdd

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

Source from the content-addressed store, hash-verified

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