Skip to content

Commit

Permalink
Update DoubleAndAdd.py: branchless
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus committed Feb 12, 2024
1 parent 34a6989 commit a50b755
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions DoubleAndAdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def double_and_add(n, x):
addend = x

for bit in bits(n):
if bit == 1:
result += addend
addend *= 2
result += addend * bit
addend <<= 2

return result

0 comments on commit a50b755

Please sign in to comment.