bf81b7198024499ad2d87ce91200d738603dde1b
7 class PowPrim
: public xtended
12 PowPrim() : xtended("powf") {}
14 virtual unsigned int arity () { return 2; }
16 virtual bool needCache () { return true; }
18 virtual Type
infereSigType (const vector
<Type
>& args
)
20 assert (args
.size() == arity());
21 //return castInterval(floatCast(args[0]|args[1]), interval()); // temporary !!!
22 return castInterval(args
[0]|args
[1], interval()); // temporary !!!
25 virtual void sigVisit (Tree sig
, sigvisitor
* visitor
) {}
27 virtual int infereSigOrder (const vector
<int>& args
) {
28 assert (args
.size() == arity());
29 return max(args
[0], args
[1]);
33 virtual Tree
computeSigOutput (const vector
<Tree
>& args
) {
35 assert (args
.size() == arity());
36 if (isNum(args
[0],n
) & isNum(args
[1],m
)) {
37 return tree(pow(double(n
), double(m
)));
39 return tree(symbol(), args
[0], args
[1]);
43 virtual string
generateCode (Klass
* klass
, const vector
<string
>& args
, const vector
<Type
>& types
)
45 assert (args
.size() == arity());
46 assert (types
.size() == arity());
48 if (types
[1]->nature() == kInt
) {
49 klass
->rememberNeedPowerDef();
50 return subst("faustpower<$1>($0)", args
[0], args
[1]);
52 return subst("pow$2($0,$1)", args
[0], args
[1], isuffix());
56 virtual string
generateLateq (Lateq
* lateq
, const vector
<string
>& args
, const vector
<Type
>& types
)
58 assert (args
.size() == arity());
59 assert (types
.size() == arity());
61 return subst("{$0}^{$1}", args
[0], args
[1]);
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; }
72 xtended
* gPowPrim
= new PowPrim();