glsl: Use M_PI_* macros.
authorMatt Turner <mattst88@gmail.com>
Sun, 6 Apr 2014 05:03:04 +0000 (22:03 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 15 Apr 2014 16:24:09 +0000 (09:24 -0700)
Notice our multiple values for M_PI_2, which rounded ...32 up to
...4 and ...5.

src/glsl/builtin_functions.cpp

index 26ea9231f73c6deb7375401dfa03b807eb9d214d..3991f9d8d8c9961fa3abeeb0ad5c2325a9138982 100644 (file)
 #include "program/prog_instruction.h"
 #include <limits>
 
+#define f(x) join(x)
+#define join(x) x ## f
+#define M_PIf f(M_PI)
+#define M_PI_2f f(M_PI_2)
+#define M_PI_4f f(M_PI_4)
+
 using namespace ir_builder;
 
 /**
@@ -2538,11 +2544,11 @@ ir_expression *
 builtin_builder::asin_expr(ir_variable *x)
 {
    return mul(sign(x),
-              sub(imm(1.5707964f),
+              sub(imm(M_PI_2f),
                   mul(sqrt(sub(imm(1.0f), abs(x))),
-                      add(imm(1.5707964f),
+                      add(imm(M_PI_2f),
                           mul(abs(x),
-                              add(imm(-0.21460183f),
+                              add(imm(M_PI_4f - 1.0f),
                                   mul(abs(x),
                                       add(imm(0.086566724f),
                                           mul(abs(x), imm(-0.03102955f))))))))));
@@ -2586,7 +2592,7 @@ builtin_builder::_acos(const glsl_type *type)
    ir_variable *x = in_var(type, "x");
    MAKE_SIG(type, always_available, 1, x);
 
-   body.emit(ret(sub(imm(1.5707964f), asin_expr(x))));
+   body.emit(ret(sub(imm(M_PI_2f), asin_expr(x))));
 
    return sig;
 }
@@ -2623,13 +2629,13 @@ builtin_builder::_atan2(const glsl_type *type)
       ir_if *inner_if = new(mem_ctx) ir_if(less(x, imm(0.0f)));
       inner_if->then_instructions.push_tail(
          if_tree(gequal(y, imm(0.0f)),
-                 assign(r, add(r, imm(3.141593f))),
-                 assign(r, sub(r, imm(3.141593f)))));
+                 assign(r, add(r, imm(M_PIf))),
+                 assign(r, sub(r, imm(M_PIf)))));
       outer_then.emit(inner_if);
 
       /* Else... */
       outer_if->else_instructions.push_tail(
-         assign(r, mul(sign(y), imm(1.5707965f))));
+         assign(r, mul(sign(y), imm(M_PI_2f))));
 
       body.emit(outer_if);