FAUST compiler  0.9.9.6b8
expprim.cpp
Go to the documentation of this file.
1 #include "xtended.hh"
2 #include "Text.hh"
3 #include <math.h>
4 
5 #include "floats.hh"
6 
7 class ExpPrim : public xtended
8 {
9 
10  public:
11 
12  ExpPrim() : xtended("exp") {}
13 
14  virtual unsigned int arity () { return 1; }
15 
16  virtual bool needCache () { return true; }
17 
18  virtual Type infereSigType (const vector<Type>& args)
19  {
20  assert (args.size() == arity());
21  return floatCast(args[0]);
22  }
23 
24  virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
25 
26  virtual int infereSigOrder (const vector<int>& args) {
27  assert (args.size() == arity());
28  return args[0];
29  }
30 
31 
32  virtual Tree computeSigOutput (const vector<Tree>& args) {
33  num n;
34  assert (args.size() == arity());
35  if (isNum(args[0],n)) {
36  return tree(exp(double(n)));
37  } else {
38  return tree(symbol(), args[0]);
39  }
40  }
41 
42  virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
43  {
44  assert (args.size() == arity());
45  assert (types.size() == arity());
46 
47  return subst("exp$1($0)", args[0], isuffix());
48  }
49 
50  virtual string generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types)
51  {
52  assert (args.size() == arity());
53  assert (types.size() == arity());
54 
55  return subst("e^{$0}", args[0]);
56  }
57 
58 };
59 
60 
62 
63 
virtual Tree computeSigOutput(const vector< Tree > &args)
Definition: expprim.cpp:32
virtual Type infereSigType(const vector< Type > &args)
Definition: expprim.cpp:18
Definition: num.hh:58
xtended * gExpPrim
Definition: expprim.cpp:61
ExpPrim()
Definition: expprim.cpp:12
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
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 int infereSigOrder(const vector< int > &args)
Definition: expprim.cpp:26
Sym symbol()
Definition: xtended.hh:24
virtual bool needCache()
Definition: expprim.cpp:16
virtual string generateCode(Klass *klass, const vector< string > &args, const vector< Type > &types)
Definition: expprim.cpp:42
Tree tree(const Node &n)
Definition: tree.hh:186
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)
Definition: expprim.cpp:50
virtual unsigned int arity()
Definition: expprim.cpp:14
virtual void sigVisit(Tree sig, sigvisitor *visitor)
Definition: expprim.cpp:24
const char * isuffix()
suffix for math functions
Definition: floats.cpp:43