00001 #include "xtended.hh"
00002 #include "Text.hh"
00003 #include <math.h>
00004
00005 #include "floats.hh"
00006
00007 class PowPrim : public xtended
00008 {
00009
00010 public:
00011
00012 PowPrim() : xtended("powf") {}
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() == arity());
00021 return castInterval(floatCast(args[0]|args[1]), interval());
00022 }
00023
00024 virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
00025
00026 virtual int infereSigOrder (const vector<int>& args) {
00027 assert (args.size() == arity());
00028 return max(args[0], args[1]);
00029 }
00030
00031
00032 virtual Tree computeSigOutput (const vector<Tree>& args) {
00033 num n,m;
00034 assert (args.size() == arity());
00035 if (isNum(args[0],n) & isNum(args[1],m)) {
00036 return tree(pow(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("pow$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("{$0}^{$1}", args[0], args[1]);
00056 }
00057
00058 };
00059
00060
00061 xtended* gPowPrim = new PowPrim();
00062
00063