3 ms·
I'm pretty sure it's not faster, but it was fun to write: float asin(float x) { float x2 = 1.0f-fabs(x); u32 i = bitcast(x2); i = 0x5f375
by AlotOfReading 7mo ago
I'm pretty sure it's not faster, but it was fun to write:
float asin(float x) {
float x2 = 1.0f-fabs(x);
u32 i = bitcast(x2);
i = 0x5f3759df - (i>>1);
float inv = bitcast(i);
return copysign(pi/2-pi/2*(x2*inv),x);
}
Courtesy of evil floating point bithacks.
- def-pri-pub 7mo ago> floating point bithacks The forbidden magic
- chuckadams 7mo agoYou brought Zalgo. I blame this decade on you.
- moffkalast 7mo ago> float asinine(float x) { FTFY :P
- adampunk 7mo ago// what the fuck
- jacquesm 7mo agoThat could do with some subtitles.
- irishcoffee 7mo agohttps://en.wikipedia.org/wiki/Fast_inverse_square_root https://en.wikipedia.org/wiki/Fast_inverse_square_root
- teo_zero 7mo agoThe bad thing about this method is that it's slower than native CPU instructions. The good thing is that the result is very precise for at least 2 values of x, namely 1.0 and -1.0 JK
- AlotOfReading 7mo agoYeah, it's an interesting approximation. It follows the shape of the curve pretty well except around 0, much better than low degree polynomials. Polynomial approximations have much better relative error bounds though.