FAUST compiler  0.9.9.6b8
tanprim.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 TanPrim : public xtended
8 {
9 
10  public:
11 
12  TanPrim() : xtended("tan") {}
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() == 1);
21  return castInterval(floatCast(args[0]), interval());
22  }
23 
24  virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
25 
26  virtual int infereSigOrder (const vector<int>& args) {
27  return args[0];
28  }
29 
30 
31  virtual Tree computeSigOutput (const vector<Tree>& args) {
32  num n;
33  if (isNum(args[0],n)) {
34  return tree(tan(double(n)));
35  } else {
36  return tree(symbol(), args[0]);
37  }
38  }
39 
40  virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
41  {
42  assert (args.size() == arity());
43  assert (types.size() == arity());
44 
45  return subst("tan$1($0)", args[0], isuffix());
46  }
47 
48  virtual string generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types)
49  {
50  assert (args.size() == arity());
51  assert (types.size() == arity());
52 
53  return subst("\\tan\\left($0\\right)", args[0]);
54  }
55 
56 };
57 
58 
60 
61 
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)
Definition: tanprim.cpp:48
virtual Tree computeSigOutput(const vector< Tree > &args)
Definition: tanprim.cpp:31
Definition: num.hh:58
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 int infereSigOrder(const vector< int > &args)
Definition: tanprim.cpp:26
virtual void sigVisit(Tree sig, sigvisitor *visitor)
Definition: tanprim.cpp:24
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 string generateCode(Klass *klass, const vector< string > &args, const vector< Type > &types)
Definition: tanprim.cpp:40
virtual bool needCache()
Definition: tanprim.cpp:16
xtended * gTanPrim
Definition: tanprim.cpp:59
Sym symbol()
Definition: xtended.hh:24
Tree tree(const Node &n)
Definition: tree.hh:186
Type castInterval(Type t, const interval &i)
Definition: sigtype.hh:278
virtual Type infereSigType(const vector< Type > &args)
Definition: tanprim.cpp:18
const char * isuffix()
suffix for math functions
Definition: floats.cpp:43
TanPrim()
Definition: tanprim.cpp:12
virtual unsigned int arity()
Definition: tanprim.cpp:14