From 60fa1a9458b012f39919a9c4070bfc4a0654d317 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 19 May 2010 12:44:23 -0700 Subject: [PATCH] builtins: Add atan(). --- builtin_function.cpp | 158 +++++++++++++++++++++++++++++++++++++++++++ builtins/110/atan | 154 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 312 insertions(+) create mode 100644 builtins/110/atan diff --git a/builtin_function.cpp b/builtin_function.cpp index f9fdd485e4b..1d847a65fb8 100644 --- a/builtin_function.cpp +++ b/builtin_function.cpp @@ -199,6 +199,163 @@ static const char *builtins_110_asin = { "))\n" }; +static const char *builtins_110_atan = { + "((function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (call asin ((expression float *\n" + " (var_ref x)\n" + " (expression float rsq\n" + " (expression float +\n" + " (expression float *\n" + " (var_ref x)\n" + " (var_ref x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ((return (call asin ((expression vec2 *\n" + " (var_ref y_over_x)\n" + " (expression vec2 rsq\n" + " (expression vec2 +\n" + " (expression vec2 *\n" + " (var_ref y_over_x)\n" + " (var_ref y_over_x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ((return (call asin ((expression vec3 *\n" + " (var_ref y_over_x)\n" + " (expression vec3 rsq\n" + " (expression vec3 +\n" + " (expression vec3 *\n" + " (var_ref y_over_x)\n" + " (var_ref y_over_x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ((return (call asin ((expression vec4 *\n" + " (var_ref y_over_x)\n" + " (expression vec4 rsq\n" + " (expression vec4 +\n" + " (expression vec4 *\n" + " (var_ref y_over_x)\n" + " (var_ref y_over_x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y)\n" + " (declare (in) float x))\n" + " ((declare () float r)\n" + " (if (expression bool >\n" + " (expression float abs (var_ref x))\n" + " (constant float (.0001)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r) (call atan ((expression float /\n" + " (var_ref y)\n" + " (var_ref x)))))\n" + " (if (expression bool <\n" + " (var_ref x)\n" + " (constant float (0.0)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r)\n" + " (expression float +\n" + " (var_ref r)\n" + " (expression float *\n" + " (expression int sign (var_ref y))\n" + " (constant float (3.1415926))))))\n" + " ()))\n" + " ())\n" + " (return (var_ref r))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ((declare () vec2 r)\n" + " (if (expression bool >\n" + " (expression vec2 abs (var_ref x))\n" + " (constant float (.0001)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r) (call atan ((expression vec2 /\n" + " (var_ref y)\n" + " (var_ref x)))))\n" + " (if (expression bool <\n" + " (var_ref x)\n" + " (constant float (0.0)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r)\n" + " (expression vec2 +\n" + " (var_ref r)\n" + " (expression vec2 *\n" + " (expression int sign (var_ref y))\n" + " (constant float (3.1415926))))))\n" + " ()))\n" + " ())\n" + " (return (var_ref r))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ((declare () vec3 r)\n" + " (if (expression bool >\n" + " (expression vec3 abs (var_ref x))\n" + " (constant float (.0001)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r) (call atan ((expression vec3 /\n" + " (var_ref y)\n" + " (var_ref x)))))\n" + " (if (expression bool <\n" + " (var_ref x)\n" + " (constant float (0.0)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r)\n" + " (expression vec3 +\n" + " (var_ref r)\n" + " (expression vec3 *\n" + " (expression int sign (var_ref y))\n" + " (constant float (3.1415926))))))\n" + " ()))\n" + " ())\n" + " (return (var_ref r))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ((declare () vec4 r)\n" + " (if (expression bool >\n" + " (expression vec4 abs (var_ref x))\n" + " (constant float (.0001)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r) (call atan ((expression vec4 /\n" + " (var_ref y)\n" + " (var_ref x)))))\n" + " (if (expression bool <\n" + " (var_ref x)\n" + " (constant float (0.0)))\n" + " ((assign (constant bool (1))\n" + " (var_ref r)\n" + " (expression vec4 +\n" + " (var_ref r)\n" + " (expression vec4 *\n" + " (expression int sign (var_ref y))\n" + " (constant float (3.1415926))))))\n" + " ()))\n" + " ())\n" + " (return (var_ref r))))\n" + "\n" + "))\n" +}; + static const char *builtins_110_ceil = { "((function ceil\n" " (signature float\n" @@ -1563,6 +1720,7 @@ static const char *functions_for_110 [] = { builtins_110_all, builtins_110_any, builtins_110_asin, + builtins_110_atan, builtins_110_ceil, builtins_110_clamp, builtins_110_cos, diff --git a/builtins/110/atan b/builtins/110/atan new file mode 100644 index 00000000000..e5542350b51 --- /dev/null +++ b/builtins/110/atan @@ -0,0 +1,154 @@ +((function atan + (signature float + (parameters + (declare (in) float x)) + ((return (call asin ((expression float * + (var_ref x) + (expression float rsq + (expression float + + (expression float * + (var_ref x) + (var_ref x)) + (constant float (1.0)))))))))) + + (signature vec2 + (parameters + (declare (in) vec2 y_over_x)) + ((return (call asin ((expression vec2 * + (var_ref y_over_x) + (expression vec2 rsq + (expression vec2 + + (expression vec2 * + (var_ref y_over_x) + (var_ref y_over_x)) + (constant float (1.0)))))))))) + + (signature vec3 + (parameters + (declare (in) vec3 y_over_x)) + ((return (call asin ((expression vec3 * + (var_ref y_over_x) + (expression vec3 rsq + (expression vec3 + + (expression vec3 * + (var_ref y_over_x) + (var_ref y_over_x)) + (constant float (1.0)))))))))) + + (signature vec4 + (parameters + (declare (in) vec4 y_over_x)) + ((return (call asin ((expression vec4 * + (var_ref y_over_x) + (expression vec4 rsq + (expression vec4 + + (expression vec4 * + (var_ref y_over_x) + (var_ref y_over_x)) + (constant float (1.0)))))))))) + + (signature float + (parameters + (declare (in) float y) + (declare (in) float x)) + ((declare () float r) + (if (expression bool > + (expression float abs (var_ref x)) + (constant float (.0001))) + ((assign (constant bool (1)) + (var_ref r) (call atan ((expression float / + (var_ref y) + (var_ref x))))) + (if (expression bool < + (var_ref x) + (constant float (0.0))) + ((assign (constant bool (1)) + (var_ref r) + (expression float + + (var_ref r) + (expression float * + (expression int sign (var_ref y)) + (constant float (3.1415926)))))) + ())) + ()) + (return (var_ref r)))) + + (signature vec2 + (parameters + (declare (in) vec2 y) + (declare (in) vec2 x)) + ((declare () vec2 r) + (if (expression bool > + (expression vec2 abs (var_ref x)) + (constant float (.0001))) + ((assign (constant bool (1)) + (var_ref r) (call atan ((expression vec2 / + (var_ref y) + (var_ref x))))) + (if (expression bool < + (var_ref x) + (constant float (0.0))) + ((assign (constant bool (1)) + (var_ref r) + (expression vec2 + + (var_ref r) + (expression vec2 * + (expression int sign (var_ref y)) + (constant float (3.1415926)))))) + ())) + ()) + (return (var_ref r)))) + + (signature vec3 + (parameters + (declare (in) vec3 y) + (declare (in) vec3 x)) + ((declare () vec3 r) + (if (expression bool > + (expression vec3 abs (var_ref x)) + (constant float (.0001))) + ((assign (constant bool (1)) + (var_ref r) (call atan ((expression vec3 / + (var_ref y) + (var_ref x))))) + (if (expression bool < + (var_ref x) + (constant float (0.0))) + ((assign (constant bool (1)) + (var_ref r) + (expression vec3 + + (var_ref r) + (expression vec3 * + (expression int sign (var_ref y)) + (constant float (3.1415926)))))) + ())) + ()) + (return (var_ref r)))) + + (signature vec4 + (parameters + (declare (in) vec4 y) + (declare (in) vec4 x)) + ((declare () vec4 r) + (if (expression bool > + (expression vec4 abs (var_ref x)) + (constant float (.0001))) + ((assign (constant bool (1)) + (var_ref r) (call atan ((expression vec4 / + (var_ref y) + (var_ref x))))) + (if (expression bool < + (var_ref x) + (constant float (0.0))) + ((assign (constant bool (1)) + (var_ref r) + (expression vec4 + + (var_ref r) + (expression vec4 * + (expression int sign (var_ref y)) + (constant float (3.1415926)))))) + ())) + ()) + (return (var_ref r)))) + +)) -- 2.30.2