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