FAUST compiler
0.9.9.6b8
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
extended
powprim.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
PowPrim
:
public
xtended
8
{
9
10
public
:
11
12
PowPrim
() :
xtended
(
"pow"
) {}
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
interval
i = args[0]->getInterval();
25
interval
j = args[1]->getInterval();
26
return
castInterval
(args[0]|args[1],
pow
(i,j));
27
28
}
29
30
virtual
void
sigVisit
(
Tree
sig,
sigvisitor
* visitor) {}
31
32
virtual
int
infereSigOrder
(
const
vector<int>& args) {
33
assert (args.size() ==
arity
());
34
return
max
(args[0], args[1]);
35
}
36
37
38
virtual
Tree
computeSigOutput
(
const
vector<Tree>& args) {
39
num
n,m;
40
assert (args.size() ==
arity
());
41
if
(
isNum
(args[0],n) &
isNum
(args[1],m)) {
42
return
tree
(
pow
(
double
(n),
double
(m)));
43
}
else
{
44
return
tree
(
symbol
(), args[0], args[1]);
45
}
46
}
47
48
virtual
string
generateCode
(
Klass
* klass,
const
vector<string>& args,
const
vector<Type>& types)
49
{
50
assert (args.size() ==
arity
());
51
assert (types.size() ==
arity
());
52
53
if
((types[1]->nature() ==
kInt
) && (types[1]->variability() ==
kKonst
) && (types[1]->computability() ==
kComp
)) {
54
klass->
rememberNeedPowerDef
();
55
return
subst
(
"faustpower<$1>($0)"
, args[0], args[1]);
56
}
else
{
57
return
subst
(
"pow$2($0,$1)"
, args[0], args[1],
isuffix
());
58
}
59
}
60
61
virtual
string
generateLateq
(
Lateq
* lateq,
const
vector<string>& args,
const
vector<Type>& types)
62
{
63
assert (args.size() ==
arity
());
64
assert (types.size() ==
arity
());
65
66
return
subst
(
"{$0}^{$1}"
, args[0], args[1]);
67
}
68
69
// power is now used as an infix binary operator, we return true to
70
// indicate that we want ^(n) to be equivalent to _^n
71
virtual
bool
isSpecialInfix
() {
return
true
; }
72
73
74
};
75
76
77
xtended
*
gPowPrim
=
new
PowPrim
();
78
79
PowPrim
Definition:
powprim.cpp:7
xtended.hh
num
Definition:
num.hh:58
pow
interval pow(const interval &x, const interval &y)
Definition:
interval.hh:213
PowPrim::generateCode
virtual string generateCode(Klass *klass, const vector< string > &args, const vector< Type > &types)
Definition:
powprim.cpp:48
isNum
bool isNum(Tree a)
Definition:
signals.hh:187
P
Definition:
smartpointer.hh:34
kInt
Definition:
sigtype.hh:54
CTree
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition:
tree.hh:109
Lateq
Definition:
lateq.hh:56
sigvisitor
Definition:
sigvisitor.hh:6
xtended
Definition:
xtended.hh:12
kComp
Definition:
sigtype.hh:57
PowPrim::PowPrim
PowPrim()
Definition:
powprim.cpp:12
max
double max(double x, double y)
Definition:
interval.hh:60
PowPrim::isSpecialInfix
virtual bool isSpecialInfix()
generaly false, but true for binary op # such that #(x) == _::x
Definition:
powprim.cpp:71
interval
Definition:
interval.hh:36
subst
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition:
Text.cpp:47
Text.hh
Klass
Definition:
klass.hh:55
PowPrim::computeSigOutput
virtual Tree computeSigOutput(const vector< Tree > &args)
Definition:
powprim.cpp:38
floats.hh
PowPrim::infereSigType
virtual Type infereSigType(const vector< Type > &args)
Definition:
powprim.cpp:18
PowPrim::needCache
virtual bool needCache()
Definition:
powprim.cpp:16
PowPrim::sigVisit
virtual void sigVisit(Tree sig, sigvisitor *visitor)
Definition:
powprim.cpp:30
xtended::symbol
Sym symbol()
Definition:
xtended.hh:24
PowPrim::infereSigOrder
virtual int infereSigOrder(const vector< int > &args)
Definition:
powprim.cpp:32
Klass::rememberNeedPowerDef
void rememberNeedPowerDef()
Definition:
klass.hh:141
tree
Tree tree(const Node &n)
Definition:
tree.hh:186
PowPrim::arity
virtual unsigned int arity()
Definition:
powprim.cpp:14
castInterval
Type castInterval(Type t, const interval &i)
Definition:
sigtype.hh:278
isuffix
const char * isuffix()
suffix for math functions
Definition:
floats.cpp:43
gPowPrim
xtended * gPowPrim
Definition:
powprim.cpp:77
PowPrim::generateLateq
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)
Definition:
powprim.cpp:61
kKonst
Definition:
sigtype.hh:56
Generated on Fri Sep 5 2014 18:06:36 for FAUST compiler by
1.8.7