GPU: Add atan_fast
This commit is contained in:
@@ -32,4 +32,23 @@ vec2 acos_fast(vec2 v)
|
||||
return v;
|
||||
}
|
||||
|
||||
float atan_fast(float x)
|
||||
{
|
||||
float a = abs(x);
|
||||
float k = a > 1.0 ? (1.0 / a) : a;
|
||||
float s = 1.0 - (1.0 - k); /* Crush denormals. */
|
||||
float t = s * s;
|
||||
/* http://mathforum.org/library/drmath/view/62672.html
|
||||
* Examined 4278190080 values of atan:
|
||||
* 2.36864877 avg ULP diff, 302 max ULP, 6.55651e-06 max error // (with denormals)
|
||||
* Examined 4278190080 values of atan:
|
||||
* 171160502 avg ULP diff, 855638016 max ULP, 6.55651e-06 max error // (crush denormals)
|
||||
*/
|
||||
float r = s * fma(0.43157974, t, 1.0) / fma(fma(0.05831938, t, 0.76443945), t, 1.0);
|
||||
if (a > 1.0) {
|
||||
r = 1.57079632679489661923 - r;
|
||||
}
|
||||
return (x < 0.0) ? -r : r;
|
||||
}
|
||||
|
||||
#endif /* GPU_SHADER_MATH_FAST_LIB_GLSL */
|
||||
|
||||
Reference in New Issue
Block a user