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

Method unsignedAdd

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

Source from the content-addressed store, hash-verified

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