Skip to content

Instantly share code, notes, and snippets.

@EmmaEwert
Created August 23, 2018 15:09
Show Gist options
  • Save EmmaEwert/73483e37eb3445ad57dac780f503aa09 to your computer and use it in GitHub Desktop.
Save EmmaEwert/73483e37eb3445ad57dac780f503aa09 to your computer and use it in GitHub Desktop.
Very fast C# implementation of `Log2`, returns nearest integer rounding up.
int FastLog2(float x) => (x.GetHashCode() >> 23) - 127;
@bobbymonboy
Copy link

You will never know how much this helped me. I was using BitConverter and a whole lot of shifting nonsense and this simplified it massively. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment