00001 #include "xtended.hh" 00002 #include "Text.hh" 00003 #include <math.h> 00004 00005 class Atan2Prim : public xtended 00006 { 00007 00008 public: 00009 00010 Atan2Prim() : xtended("atan2") {} 00011 00012 virtual unsigned int arity () { return 2; } 00013 00014 virtual bool needCache () { return true; } 00015 00016 virtual Type infereSigType (const vector<Type>& args) 00017 { 00018 assert (args.size() == 2); 00019 return floatCast(args[0]|args[1]); 00020 } 00021 00022 virtual void sigVisit (Tree sig, sigvisitor* visitor) {} 00023 00024 virtual int infereSigOrder (const vector<int>& args) { 00025 return max(args[0], args[1]); 00026 } 00027 00028 00029 virtual Tree computeSigOutput (const vector<Tree>& args) 00030 { 00031 assert (args.size() == 2); 00032 num n,m; 00033 if (isNum(args[0],n) && isNum(args[1],m)) { 00034 return tree(atan2f(float(n), float(m))); 00035 } else { 00036 return tree(symbol(), args[0], args[1]); 00037 } 00038 } 00039 00040 virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types) 00041 { 00042 return subst("atan2f($0, $1)", args[0], args[1]); 00043 } 00044 00045 }; 00046 00047 00048 xtended* gAtan2Prim = new Atan2Prim(); 00049 00050