FAUST compiler  0.9.9.6b8
rintprim.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 RintPrim : public xtended
9 {
10 
11  public:
12 
13  RintPrim() : xtended("rint") {}
14 
15  virtual unsigned int arity () { return 1; }
16 
17  virtual bool needCache () { return true; }
18 
19  virtual Type infereSigType (const vector<Type>& args)
20  {
21  assert (args.size() == arity());
22  interval i = args[0]->getInterval();
23  if (i.valid) {
24  return castInterval(floatCast(args[0]), interval(rint(i.lo), rint(i.hi)));
25  } else {
26  return floatCast(args[0]);
27  }
28  }
29 
30  virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
31 
32  virtual int infereSigOrder (const vector<int>& args) {
33  assert (args.size() == arity());
34  return args[0];
35  }
36 
37 
38  virtual Tree computeSigOutput (const vector<Tree>& args) {
39  num n;
40  assert (args.size() == arity());
41  if (isNum(args[0],n)) {
42  return tree(rint(double(n)));
43  } else {
44  return tree(symbol(), args[0]);
45  }
46  }
47 
48  virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
49  {
50  assert (args.size() == arity());
51  assert (types.size() == arity());
52 
53  return subst("rint$1($0)", args[0], isuffix());
54  }
55 
56  virtual string generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types)
57  {
58  assert (args.size() == arity());
59  assert (types.size() == arity());
60 
61  return subst("\\left[ {$0} \\right]", args[0]);
62  }
63 
64 };
65 
66 
68 
69 
Definition: num.hh:58
virtual int infereSigOrder(const vector< int > &args)
Definition: rintprim.cpp:32
bool isNum(Tree a)
Definition: signals.hh:187
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Definition: lateq.hh:56
virtual Type infereSigType(const vector< Type > &args)
Definition: rintprim.cpp:19
xtended * gRintPrim
Definition: rintprim.cpp:67
Type floatCast(Type t)
Definition: sigtype.hh:270
virtual string generateCode(Klass *klass, const vector< string > &args, const vector< Type > &types)
Definition: rintprim.cpp:48
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
Definition: klass.hh:55
RintPrim()
Definition: rintprim.cpp:13
virtual bool needCache()
Definition: rintprim.cpp:17
Sym symbol()
Definition: xtended.hh:24
Tree tree(const Node &n)
Definition: tree.hh:186
virtual Tree computeSigOutput(const vector< Tree > &args)
Definition: rintprim.cpp:38
virtual unsigned int arity()
Definition: rintprim.cpp:15
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)
Definition: rintprim.cpp:56
Type castInterval(Type t, const interval &i)
Definition: sigtype.hh:278
const char * isuffix()
suffix for math functions
Definition: floats.cpp:43
virtual void sigVisit(Tree sig, sigvisitor *visitor)
Definition: rintprim.cpp:30