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