Skip to content

Instantly share code, notes, and snippets.

@sanjoy
Created September 6, 2015 06:57
Show Gist options
  • Save sanjoy/cedce4ee4e0f71f982a1 to your computer and use it in GitHub Desktop.
Save sanjoy/cedce4ee4e0f71f982a1 to your computer and use it in GitHub Desktop.
template<typename T>
bool is_even_0(T v) {
// v is odd iff it has an multiplicative inverse modulo 2^bitwidth(T)
for (T i = 1; i != 0; i++)
if (T(v * i) == T(1))
return false; // odd
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment