MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / add

Function add

maths/addition_without_arithmetic.py:9–29  ·  view source on GitHub ↗

Implementation of addition of integer Examples: >>> add(3, 5) 8 >>> add(13, 5) 18 >>> add(-7, 2) -5 >>> add(0, -7) -7 >>> add(-321, 0) -321

(first: int, second: int)

Source from the content-addressed store, hash-verified

7
8
9def add(first: int, second: int) -> int:
10 """
11 Implementation of addition of integer
12
13 Examples:
14 >>> add(3, 5)
15 8
16 >>> add(13, 5)
17 18
18 >>> add(-7, 2)
19 -5
20 >>> add(0, -7)
21 -7
22 >>> add(-321, 0)
23 -321
24 """
25 while second != 0:
26 c = first & second
27 first ^= second
28 second = c << 1
29 return first
30
31
32if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected