[libcxx-commits] [PATCH] D70640: Optimize std::midpoint for signed integers
Andrej Korman via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Nov 24 04:21:25 PST 2019
Aj0SK added a comment.
Maybe I would add explanation why the term
(__a & __b) + ((__a ^ __b) >> 1)
calculates the floored average. Adding a and b can be rewritten as a + b = (a ^ b) + ((a & b) << 1) . After this we have to divide a+b by 2. This can be done also using shifting to right by 1. After this we get (a + b)/2 = ((a ^ b) >>1) + (a & b).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70640/new/
https://reviews.llvm.org/D70640
More information about the libcxx-commits
mailing list