FAUST compiler
0.9.9.6b8
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
extended
absprim.cpp
Go to the documentation of this file.
1
#include "
xtended.hh
"
2
#include "
Text.hh
"
3
#include <math.h>
4
#include "
sigtyperules.hh
"
5
6
#include "
floats.hh
"
7
8
class
AbsPrim
:
public
xtended
9
{
10
11
public
:
12
13
AbsPrim
() :
xtended
(
"abs"
) {}
14
15
virtual
unsigned
int
arity
() {
return
1; }
16
17
virtual
bool
needCache
() {
return
true
; }
18
19
virtual
Type
infereSigType
(
const
vector<Type>& types)
20
{
21
assert (types.size() ==
arity
());
22
Type
t = types[0];
23
return
castInterval
(t,
abs
(t->getInterval()));
24
return
t;
25
}
26
27
virtual
void
sigVisit
(
Tree
sig,
sigvisitor
* visitor) {}
28
29
virtual
int
infereSigOrder
(
const
vector<int>& args)
30
{
31
assert (args.size() ==
arity
());
32
return
args[0];
33
}
34
35
36
virtual
Tree
computeSigOutput
(
const
vector<Tree>& args)
37
{
38
double
f;
int
i;
39
40
assert (args.size() ==
arity
());
41
42
if
(
isDouble
(args[0]->node(),&f)) {
43
return
tree
(fabs(f));
44
45
}
else
if
(
isInt
(args[0]->node(),&i)) {
46
return
tree
(
abs
(i));
47
48
}
else
{
49
return
tree
(
symbol
(), args[0]);
50
}
51
}
52
53
virtual
string
generateCode
(
Klass
* klass,
const
vector<string>& args,
const
vector<Type>& types)
54
{
55
assert (args.size() ==
arity
());
56
assert (types.size() ==
arity
());
57
58
Type
t =
infereSigType
(types);
59
if
(t->nature() ==
kReal
) {
60
return
subst
(
"fabs$1($0)"
, args[0],
isuffix
());
61
}
else
{
62
return
subst
(
"abs($0)"
, args[0]);
63
}
64
}
65
66
virtual
string
generateLateq
(
Lateq
* lateq,
const
vector<string>& args,
const
vector<Type>& types)
67
{
68
assert (args.size() ==
arity
());
69
assert (types.size() ==
arity
());
70
71
Type
t =
infereSigType
(types);
72
return
subst
(
"\\left\\lvert{$0}\\right\\rvert"
, args[0]);
73
}
74
};
75
76
77
xtended
*
gAbsPrim
=
new
AbsPrim
();
78
79
xtended.hh
AbsPrim::AbsPrim
AbsPrim()
Definition:
absprim.cpp:13
P
Definition:
smartpointer.hh:34
abs
interval abs(const interval &x)
Definition:
interval.hh:226
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
AbsPrim::arity
virtual unsigned int arity()
Definition:
absprim.cpp:15
xtended
Definition:
xtended.hh:12
AbsPrim::infereSigOrder
virtual int infereSigOrder(const vector< int > &args)
Definition:
absprim.cpp:29
gAbsPrim
xtended * gAbsPrim
Definition:
absprim.cpp:77
subst
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition:
Text.cpp:47
Text.hh
Klass
Definition:
klass.hh:55
AbsPrim
Definition:
absprim.cpp:8
AbsPrim::sigVisit
virtual void sigVisit(Tree sig, sigvisitor *visitor)
Definition:
absprim.cpp:27
isDouble
bool isDouble(const Node &n)
Definition:
node.hh:143
floats.hh
AbsPrim::generateCode
virtual string generateCode(Klass *klass, const vector< string > &args, const vector< Type > &types)
Definition:
absprim.cpp:53
kReal
Definition:
sigtype.hh:54
xtended::symbol
Sym symbol()
Definition:
xtended.hh:24
AbsPrim::needCache
virtual bool needCache()
Definition:
absprim.cpp:17
tree
Tree tree(const Node &n)
Definition:
tree.hh:186
castInterval
Type castInterval(Type t, const interval &i)
Definition:
sigtype.hh:278
isuffix
const char * isuffix()
suffix for math functions
Definition:
floats.cpp:43
AbsPrim::infereSigType
virtual Type infereSigType(const vector< Type > &types)
Definition:
absprim.cpp:19
sigtyperules.hh
API to the typing system of signals.
isInt
bool isInt(const Node &n)
Definition:
node.hh:126
AbsPrim::generateLateq
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)
Definition:
absprim.cpp:66
AbsPrim::computeSigOutput
virtual Tree computeSigOutput(const vector< Tree > &args)
Definition:
absprim.cpp:36
Generated on Fri Sep 5 2014 18:06:36 for FAUST compiler by
1.8.7