8 class SqrtPrim
: public xtended
13 SqrtPrim() : xtended("sqrt") {}
15 virtual unsigned int arity () { return 1; }
17 virtual bool needCache () { return true; }
19 virtual Type
infereSigType (const vector
<Type
>& args
)
21 assert (args
.size() == 1);
23 interval i
= t
->getInterval();
24 if (i
.valid
&& i
.lo
>=0) {
25 return castInterval(floatCast(t
), interval(sqrt(i
.lo
), sqrt(i
.hi
)));
27 return castInterval(floatCast(t
), interval());
31 virtual void sigVisit (Tree sig
, sigvisitor
* visitor
) {}
33 virtual int infereSigOrder (const vector
<int>& args
) {
38 virtual Tree
computeSigOutput (const vector
<Tree
>& args
) {
39 // verifier les simplifications
41 if (isNum(args
[0],n
)) {
42 return tree(sqrt(double(n
)));
44 return tree(symbol(), args
[0]);
48 virtual string
generateCode (Klass
* klass
, const vector
<string
>& args
, const vector
<Type
>& types
)
50 assert (args
.size() == arity());
51 assert (types
.size() == arity());
53 return subst("sqrt$1($0)", args
[0], 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("\\sqrt{$0}", args
[0]);
67 xtended
* gSqrtPrim
= new SqrtPrim();