00001 #include "xtended.hh"
00002 #include "Text.hh"
00003 #include <math.h>
00004
00005 class PowPrim : public xtended
00006 {
00007
00008 public:
00009
00010 PowPrim() : xtended("powf") {}
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() == arity());
00019 return castInterval(floatCast(args[0]|args[1]), interval());
00020 }
00021
00022 virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
00023
00024 virtual int infereSigOrder (const vector<int>& args) {
00025 assert (args.size() == arity());
00026 return max(args[0], args[1]);
00027 }
00028
00029
00030 virtual Tree computeSigOutput (const vector<Tree>& args) {
00031 num n,m;
00032 assert (args.size() == arity());
00033 if (isNum(args[0],n) & isNum(args[1],m)) {
00034 return tree(powf(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 assert (args.size() == arity());
00043 return subst("powf($0, $1)", args[0], args[1]);
00044 }
00045
00046 };
00047
00048
00049 xtended* gPowPrim = new PowPrim();
00050
00051