2b54eea0fc2d9db0efe5d368015d39daa2c41c70
4 #include "sigtyperules.hh"
8 class AbsPrim
: public xtended
13 AbsPrim() : xtended("abs") {}
15 virtual unsigned int arity () { return 1; }
17 virtual bool needCache () { return true; }
19 virtual Type
infereSigType (const vector
<Type
>& types
)
21 assert (types
.size() == arity());
23 return castInterval(t
, abs(t
->getInterval()));
27 virtual void sigVisit (Tree sig
, sigvisitor
* visitor
) {}
29 virtual int infereSigOrder (const vector
<int>& args
)
31 assert (args
.size() == arity());
36 virtual Tree
computeSigOutput (const vector
<Tree
>& args
)
40 assert (args
.size() == arity());
42 if (isDouble(args
[0]->node(),&f
)) {
45 } else if (isInt(args
[0]->node(),&i
)) {
49 return tree(symbol(), args
[0]);
53 virtual string
generateCode (Klass
* klass
, const vector
<string
>& args
, const vector
<Type
>& types
)
55 assert (args
.size() == arity());
56 assert (types
.size() == arity());
58 Type t
= infereSigType(types
);
59 if (t
->nature() == kReal
) {
60 return subst("fabs$1($0)", args
[0], isuffix());
62 return subst("abs($0)", args
[0]);
66 virtual string
generateLateq (Lateq
* lateq
, const vector
<string
>& args
, const vector
<Type
>& types
)
68 assert (args
.size() == arity());
69 assert (types
.size() == arity());
71 Type t
= infereSigType(types
);
72 return subst("\\left\\lvert{$0}\\right\\rvert", args
[0]);
77 xtended
* gAbsPrim
= new AbsPrim();