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