FAUST compiler  0.9.9.6b8
remainderprim.cpp
Go to the documentation of this file.
00001 #include "xtended.hh"
00002 #include "compatibility.hh"
00003 #include "Text.hh"
00004 #include <math.h>
00005 
00006 #include "floats.hh"
00007 
00008 class RemainderPrim : public xtended
00009 {
00010 
00011  public:
00012  
00013     RemainderPrim() : xtended("remainder") {}
00014     
00015     virtual unsigned int arity () { return 2; }
00016     
00017     virtual bool    needCache ()    { return true; }
00018     
00019     virtual Type    infereSigType (const vector<Type>& args)
00020     {
00021         assert (args.size() == arity());
00022         return castInterval(floatCast(args[0]|args[1]), interval());   // temporary rule !!!
00023     }
00024     
00025     virtual void    sigVisit (Tree sig, sigvisitor* visitor) {} 
00026     
00027     virtual int infereSigOrder (const vector<int>& args) {
00028         assert (args.size() == arity());
00029         return max(args[0], args[1]);
00030     }
00031 
00032     
00033     virtual Tree    computeSigOutput (const vector<Tree>& args) {
00034         num n,m;
00035         assert (args.size() == arity());
00036         if (isNum(args[0],n) & isNum(args[1],m)) {
00037             return tree(remainder(double(n), double(m)));
00038         } else {
00039             return tree(symbol(), args[0], args[1]);
00040         }
00041     }
00042         
00043     virtual string  generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
00044     {
00045         assert (args.size() == arity());
00046         assert (types.size() == arity());
00047         
00048         return subst("remainder$2($0,$1)", args[0], args[1], isuffix());
00049     }
00050     
00051     virtual string  generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types)
00052     {
00053         assert (args.size() == arity());
00054         assert (types.size() == arity());
00055         
00056         return subst("$0\\pmod{$1}", args[0], args[1]); // Same as fmodprim.cpp.
00057     }
00058     
00059 };
00060 
00061 
00062 xtended* gRemainderPrim = new RemainderPrim();
00063 
00064