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