FAUST compiler
0.9.9.6b8
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
extended
sqrtprim.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
8
class
SqrtPrim
:
public
xtended
9
{
10
11
public
:
12
13
SqrtPrim
() :
xtended
(
"sqrt"
) {}
14
15
virtual
unsigned
int
arity
() {
return
1; }
16
17
virtual
bool
needCache
() {
return
true
; }
18
19
virtual
Type
infereSigType
(
const
vector<Type>& args)
20
{
21
assert (args.size() == 1);
22
Type
t = args[0];
23
interval
i = t->getInterval();
24
if
(i.
valid
&& i.
lo
>=0) {
25
return
castInterval
(
floatCast
(t),
interval
(sqrt(i.
lo
), sqrt(i.
hi
)));
26
}
else
{
27
return
castInterval
(
floatCast
(t),
interval
());
28
}
29
}
30
31
virtual
void
sigVisit
(
Tree
sig,
sigvisitor
* visitor) {}
32
33
virtual
int
infereSigOrder
(
const
vector<int>& args) {
34
return
args[0];
35
}
36
37
38
virtual
Tree
computeSigOutput
(
const
vector<Tree>& args) {
39
// verifier les simplifications
40
num
n;
41
if
(
isNum
(args[0],n)) {
42
return
tree
(sqrt(
double
(n)));
43
}
else
{
44
return
tree
(
symbol
(), args[0]);
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
return
subst
(
"sqrt$1($0)"
, args[0],
isuffix
());
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
(
"\\sqrt{$0}"
, args[0]);
62
}
63
64
};
65
66
67
xtended
*
gSqrtPrim
=
new
SqrtPrim
();
68
69
interval::valid
bool valid
true if it is a valid interval
Definition:
interval.hh:38
xtended.hh
interval::lo
double lo
minimal value
Definition:
interval.hh:39
num
Definition:
num.hh:58
isNum
bool isNum(Tree a)
Definition:
signals.hh:187
P
Definition:
smartpointer.hh:34
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
SqrtPrim::sigVisit
virtual void sigVisit(Tree sig, sigvisitor *visitor)
Definition:
sqrtprim.cpp:31
gSqrtPrim
xtended * gSqrtPrim
Definition:
sqrtprim.cpp:67
SqrtPrim::infereSigType
virtual Type infereSigType(const vector< Type > &args)
Definition:
sqrtprim.cpp:19
interval
Definition:
interval.hh:36
SqrtPrim::generateCode
virtual string generateCode(Klass *klass, const vector< string > &args, const vector< Type > &types)
Definition:
sqrtprim.cpp:48
floatCast
Type floatCast(Type t)
Definition:
sigtype.hh:270
subst
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition:
Text.cpp:47
SqrtPrim::needCache
virtual bool needCache()
Definition:
sqrtprim.cpp:17
Text.hh
Klass
Definition:
klass.hh:55
floats.hh
SqrtPrim
Definition:
sqrtprim.cpp:8
SqrtPrim::infereSigOrder
virtual int infereSigOrder(const vector< int > &args)
Definition:
sqrtprim.cpp:33
xtended::symbol
Sym symbol()
Definition:
xtended.hh:24
SqrtPrim::SqrtPrim
SqrtPrim()
Definition:
sqrtprim.cpp:13
SqrtPrim::computeSigOutput
virtual Tree computeSigOutput(const vector< Tree > &args)
Definition:
sqrtprim.cpp:38
tree
Tree tree(const Node &n)
Definition:
tree.hh:186
SqrtPrim::arity
virtual unsigned int arity()
Definition:
sqrtprim.cpp:15
castInterval
Type castInterval(Type t, const interval &i)
Definition:
sigtype.hh:278
isuffix
const char * isuffix()
suffix for math functions
Definition:
floats.cpp:43
SqrtPrim::generateLateq
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)
Definition:
sqrtprim.cpp:56
interval::hi
double hi
maximal value
Definition:
interval.hh:40
Generated on Fri Sep 5 2014 18:06:37 for FAUST compiler by
1.8.7