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

Method unsignedAdd

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

Source from the content-addressed store, hash-verified

1073 }
1074
1075 private function unsignedAdd(string $left, string $right): string {
1076 $length = max(strlen($left), strlen($right));
1077 $left = str_pad($left, $length, '0', STR_PAD_LEFT);
1078 $right = str_pad($right, $length, '0', STR_PAD_LEFT);
1079 $result = '';
1080 $carry = 0;
1081 for ($index = $length - 1; $index >= 0; $index--) {
1082 $sum = (int)$left[$index] + (int)$right[$index] + $carry;
1083 $result = (string)($sum % 10) . $result;
1084 $carry = intdiv($sum, 10);
1085 }
1086 return ($carry > 0 ? (string)$carry : '') . $result;
1087 }
1088
1089 private function unsignedSubtract(string $left, string $right): string {
1090 $right = str_pad($right, strlen($left), '0', STR_PAD_LEFT);

Callers 2

decimalAddMethod · 0.95
decimalDivideMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected