Skip to content

Instantly share code, notes, and snippets.

@FernandoS27
Created September 1, 2018 16:33
Show Gist options
  • Save FernandoS27/0b3b0e3c5e8b8912f6df1907425977f3 to your computer and use it in GitHub Desktop.
Save FernandoS27/0b3b0e3c5e8b8912f6df1907425977f3 to your computer and use it in GitHub Desktop.
unsigned int approx(float f) {
float ax = fabs(f);
unsigned int extra = 1;
if (ax >= 128.f) {
ax = 129.f;
extra = 0;
}
double w;
float ax2 = modf(ax, &w);
unsigned int sign = (f < 0.0f) << 31;
return sign | ((((int)ax) << 23) | (int)(ax2 * 8388607.f) + extra);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment