FAUST compiler  0.9.9.6b8
atan2prim.cpp
Go to the documentation of this file.
00001 #include "xtended.hh"
00002 #include "Text.hh"
00003 #include <math.h>
00004 
00005 #include "floats.hh"
00006 
00007 class Atan2Prim : public xtended
00008 {
00009 
00010  public:
00011  
00012     Atan2Prim() : xtended("atan2") {}
00013     
00014     virtual unsigned int    arity () { return 2; }
00015     
00016     virtual bool    needCache ()    { return true; }
00017     
00018     virtual Type    infereSigType (const vector<Type>& args)
00019     {
00020         assert (args.size() == 2);
00021         return floatCast(args[0]|args[1]);
00022     }
00023     
00024     virtual void    sigVisit (Tree sig, sigvisitor* visitor) {} 
00025     
00026     virtual int infereSigOrder (const vector<int>& args) {
00027         return max(args[0], args[1]);
00028     }
00029 
00030     
00031     virtual Tree    computeSigOutput (const vector<Tree>& args) 
00032     {
00033         assert (args.size() == 2);
00034         num n,m;
00035         if (isNum(args[0],n) && isNum(args[1],m)) {
00036             return tree(atan2(double(n), double(m)));
00037         } else {
00038             return tree(symbol(), args[0], args[1]);
00039         }
00040     }
00041         
00042     virtual string  generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
00043     {
00044         assert (args.size() == arity());
00045         assert (types.size() == arity());
00046         
00047         return subst("atan2$2($0,$1)", args[0], args[1], isuffix());
00048     }
00049     
00050     virtual string  generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types)
00051     {
00052         assert (args.size() == arity());
00053         assert (types.size() == arity());
00054         
00055         return subst("\\arctan\\frac{$0}{$1}", args[0], args[1]);
00056     }
00057     
00058 };
00059 
00060 
00061 xtended* gAtan2Prim = new Atan2Prim();
00062 
00063