Created
September 1, 2018 16:33
-
-
Save FernandoS27/0b3b0e3c5e8b8912f6df1907425977f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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