average_round_up.txt
1 ==== Average, rounded up 2 3 .Implementation 4 [source] 5 ---- 6 template<class T> T average_round_up(T x, T y) { 7 return (x | y) - ((x ^ y) >> 1); 8 } 9 ---- 10 11 .Proof 12 [source] 13 ---- 14 int main() { 15 unsigned x = nondet_unsigned(); 16 unsigned y = nondet_unsigned(); 17 unsigned z = average_round_up(x, y); 18 unsigned w = (uint64_t(x) + y + 1) / 2; 19 assert(z == w); 20 return 0; 21 } 22 ----