Add atan2

Issue #47 resolved
Jan Blechta created an issue

I can't push to repo so I suggest:

commit f03a21c5eed7dc0db2986e3a688ebf4f28a6816f
Author: Jan Blechta <blechta@karlin.mff.cuni.cz>
Date:   Fri May 29 12:16:52 2015 +0200

    Add atan_2(y, x).

diff --git a/uflacs/analysis/graph_rebuild.py b/uflacs/analysis/graph_rebuild.py
index f689fc7..941b551 100644
--- a/uflacs/analysis/graph_rebuild.py
+++ b/uflacs/analysis/graph_rebuild.py
@@ -72,6 +72,7 @@ class ReconstructScalarSubexpressions(MultiFunction):
     # Binary scalar functions
     power = scalar_nary
     bessel_function = scalar_nary  # TODO: Is this ok?
+    atan_2 = scalar_nary

     def condition(self, o, ops):
         sops = [op[0] for op in ops]
diff --git a/uflacs/codeutils/cpp_expr_formatting_rules.py b/uflacs/codeutils/cpp_expr_formatting_rules.py
index 8db0de7..aaaf9b9 100644
--- a/uflacs/codeutils/cpp_expr_formatting_rules.py
+++ b/uflacs/codeutils/cpp_expr_formatting_rules.py
@@ -150,6 +150,9 @@ class CppFormattingRules(object):
     def atan(self, o, op):
         return self._cmath("atan", op)

+    def atan_2(self, o, y, x):
+        return "{0}atan2({1}, {2})".format("std::", y, x)
+
     def erf(self, o, op):
         # return self._cmath("erf", op) # C++11 stl has this function
         return "erf({0})".format(op)

Comments (3)

  1. Martin Sandve Alnæs

    The code generation is rewritten in the branch I'm working on so I've added it there instead.

  2. Log in to comment