The average of two unsigned integers, rounding toward zero, sounds easy. But it gives the wrong answer in the face of integer overflow. For example, if unsigned integers are 32 bits wide, then it says that average(0x80000000U, 0x8000000U) is zero.

•10m read time•From devblogs.microsoft.com
Post cover image
Share this post