Add /usr/local/lib/faustine and /usr/lib/faustine to preprocessor import path.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / extended / powprim.cpp
1 #include "xtended.hh"
2 #include "Text.hh"
3 #include <math.h>
4
5 #include "floats.hh"
6
7 class PowPrim : public xtended
8 {
9
10 public:
11
12 PowPrim() : xtended("powf") {}
13
14 virtual unsigned int arity () { return 2; }
15
16 virtual bool needCache () { return true; }
17
18 virtual Type infereSigType (const vector<Type>& args)
19 {
20 assert (args.size() == arity());
21 //return castInterval(floatCast(args[0]|args[1]), interval()); // temporary !!!
22 return castInterval(args[0]|args[1], interval()); // temporary !!!
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(pow(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 if (types[1]->nature() == kInt) {
49 klass->rememberNeedPowerDef();
50 return subst("faustpower<$1>($0)", args[0], args[1]);
51 } else {
52 return subst("pow$2($0,$1)", args[0], args[1], isuffix());
53 }
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("{$0}^{$1}", args[0], args[1]);
62 }
63
64 // power is now used as an infix binary operator, we return true to
65 // indicate that we want ^(n) to be equivalent to _^n
66 virtual bool isSpecialInfix() { return true; }
67
68
69 };
70
71
72 xtended* gPowPrim = new PowPrim();
73
74