FAUST compiler  0.9.9.6b8
remainderprim.cpp
Go to the documentation of this file.
1 #include "xtended.hh"
2 #include "compatibility.hh"
3 #include "Text.hh"
4 #include <math.h>
5 
6 #include "floats.hh"
7 
8 class RemainderPrim : public xtended
9 {
10 
11  public:
12 
13  RemainderPrim() : xtended("remainder") {}
14 
15  virtual unsigned int arity () { return 2; }
16 
17  virtual bool needCache () { return true; }
18 
19  virtual Type infereSigType (const vector<Type>& args)
20  {
21  assert (args.size() == arity());
22  return castInterval(floatCast(args[0]|args[1]), interval()); // temporary rule !!!
23  }
24 
25  virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
26 
27  virtual int infereSigOrder (const vector<int>& args) {
28  assert (args.size() == arity());
29  return max(args[0], args[1]);
30  }
31 
32 
33  virtual Tree computeSigOutput (const vector<Tree>& args) {
34  num n,m;
35  assert (args.size() == arity());
36  if (isNum(args[0],n) & isNum(args[1],m)) {
37  return tree(remainder(double(n), double(m)));
38  } else {
39  return tree(symbol(), args[0], args[1]);
40  }
41  }
42 
43  virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
44  {
45  assert (args.size() == arity());
46  assert (types.size() == arity());
47 
48  return subst("remainder$2($0,$1)", args[0], args[1], isuffix());
49  }
50 
51  virtual string generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types)
52  {
53  assert (args.size() == arity());
54  assert (types.size() == arity());
55 
56  return subst("$0\\pmod{$1}", args[0], args[1]); // Same as fmodprim.cpp.
57  }
58 
59 };
60 
61 
63 
64 
virtual int infereSigOrder(const vector< int > &args)
Definition: num.hh:58
xtended * gRemainderPrim
bool isNum(Tree a)
Definition: signals.hh:187
virtual void sigVisit(Tree sig, sigvisitor *visitor)
virtual string generateCode(Klass *klass, const vector< string > &args, const vector< Type > &types)
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Definition: lateq.hh:56
double max(double x, double y)
Definition: interval.hh:60
virtual unsigned int arity()
Type floatCast(Type t)
Definition: sigtype.hh:270
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
Definition: klass.hh:55
virtual bool needCache()
Sym symbol()
Definition: xtended.hh:24
virtual Tree computeSigOutput(const vector< Tree > &args)
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)
Tree tree(const Node &n)
Definition: tree.hh:186
Type castInterval(Type t, const interval &i)
Definition: sigtype.hh:278
const char * isuffix()
suffix for math functions
Definition: floats.cpp:43
virtual Type infereSigType(const vector< Type > &args)