Completing basic operations in basic.ml for primitives float, And, Or, Xor, fmod...
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / extended / remainderprim.cpp
1 #include "xtended.hh"
2 #include "compatibility.hh"
3 #include "Text.hh"
4 #include <math.h>
5
6 #include "floats.hh"
7
8 class RemainderPrim : public xtended
9 {
10
11 public:
12
13 RemainderPrim() : xtended("remainder") {}
14
15 virtual unsigned int arity () { return 2; }
16
17 virtual bool needCache () { return true; }
18
19 virtual Type infereSigType (const vector<Type>& args)
20 {
21 assert (args.size() == arity());
22 return castInterval(floatCast(args[0]|args[1]), interval()); // temporary rule !!!
23 }
24
25 virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
26
27 virtual int infereSigOrder (const vector<int>& args) {
28 assert (args.size() == arity());
29 return max(args[0], args[1]);
30 }
31
32
33 virtual Tree computeSigOutput (const vector<Tree>& args) {
34 num n,m;
35 assert (args.size() == arity());
36 if (isNum(args[0],n) & isNum(args[1],m)) {
37 return tree(remainder(double(n), double(m)));
38 } else {
39 return tree(symbol(), args[0], args[1]);
40 }
41 }
42
43 virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
44 {
45 assert (args.size() == arity());
46 assert (types.size() == arity());
47
48 return subst("remainder$2($0,$1)", args[0], args[1], isuffix());
49 }
50
51 virtual string generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types)
52 {
53 assert (args.size() == arity());
54 assert (types.size() == arity());
55
56 return subst("$0\\pmod{$1}", args[0], args[1]); // Same as fmodprim.cpp.
57 }
58
59 };
60
61
62 xtended* gRemainderPrim = new RemainderPrim();
63
64