Skip to content

Instantly share code, notes, and snippets.

@Subv
Forked from FernandoS27/RRO.EX2
Created September 1, 2018 22:08
Show Gist options
  • Save Subv/76a3e7509e6127a9838383ab3f215ecd to your computer and use it in GitHub Desktop.
Save Subv/76a3e7509e6127a9838383ab3f215ecd 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