diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2008-07-17 10:03:10 -0600 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2008-07-17 10:04:56 -0600 |
commit | 91de7b6cd30ad5ec00dd94ea4a56ec0c9056948f (patch) | |
tree | f5c62b47c00c2198624f0bc43f9dfda008c30a1d /src/mesa/shader/slang | |
parent | 8336fbc35c990f6bce0ee997acae8652cd44fd97 (diff) | |
download | external_mesa3d-91de7b6cd30ad5ec00dd94ea4a56ec0c9056948f.zip external_mesa3d-91de7b6cd30ad5ec00dd94ea4a56ec0c9056948f.tar.gz external_mesa3d-91de7b6cd30ad5ec00dd94ea4a56ec0c9056948f.tar.bz2 |
mesa: fix/improve the atan(y,x) function
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r-- | src/mesa/shader/slang/library/slang_common_builtin.gc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index b095a64..3726335 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -401,16 +401,17 @@ vec4 atan(const vec4 y_over_x) float atan(const float y, const float x) { - if (x == 0.0) - return 0.0; - float z = atan(y / x); - if (x < 0.0) - { - if (y < 0.0) - return z - 3.141593; - return z + 3.141593; - } - return z; + float r; + if (abs(x) > 1.0e-4) { + r = atan(y / x); + if (x < 0.0) { + r = r + sign(y) * 3.141593; + } + } + else { + r = sign(y) * 1.5707965; // pi/2 + } + return r; } vec2 atan(const vec2 u, const vec2 v) |