News for hackers. Stuff that matters.
Re:Ten Ways to Check if an Integer Is a Power Of Two in C by MostAwesomeDude on Tuesday July 26, 2011 @12:28PM (#2808102)
And fast; Mesa uses this.

  static INLINE boolean
  util_is_power_of_two( unsigned v )
  {
     return (v & (v-1)) == 0;
  }
Re:Ten Ways to Check if an Integer Is a Power Of Two in C by ColinWright on Tuesday July 26, 2011 @01:10PM (#2808363)
Returns True when v==0, and yet 0 is not a power of 2.

Further, this technique - correctly applied - is essentially #9 in the list.

Re:Ten Ways to Check if an Integer Is a Power Of Two in C by vog on Wednesday July 27, 2011 @09:30AM (#2812019)
According to the C spec, this is expression is undefined for v == 0.

So it might return true, or return false, or start NetHack, or wipe your disk. In other words: Strictly speaken, that function is not allowed to be called for v == 0.

Re:Ten Ways to Check if an Integer Is a Power Of Two in C by MostAwesomeDude on Thursday July 28, 2011 @09:39AM (#2816714)
Mesa is a GL renderer. POT only matters in 3D for things like texture sizes. Textures aren't allowed to have zero-sized dimensions. The check for v == 0 occurs far higher up the stack than where this function's used.

We're not writing bad code, we promise. :3