1 /************************************************************************
2  ************************************************************************
3     FAUST compiler
4     Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
5     ---------------------------------------------------------------------
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
21 
22 #include <math.h>
23 
24 #include "Text.hh"
25 #include "floats.hh"
26 #include "xtended.hh"
27 
28 class AtanPrim : public xtended {
29    public:
AtanPrim()30     AtanPrim() : xtended("atan") {}
31 
arity()32     virtual unsigned int arity() { return 1; }
33 
needCache()34     virtual bool needCache() { return true; }
35 
infereSigType(const vector<::Type> & args)36     virtual ::Type infereSigType(const vector< ::Type>& args)
37     {
38         faustassert(args.size() == 1);
39         return floatCast(args[0]);
40     }
41 
infereSigOrder(const vector<int> & args)42     virtual int infereSigOrder(const vector<int>& args) { return args[0]; }
43 
computeSigOutput(const vector<Tree> & args)44     virtual Tree computeSigOutput(const vector<Tree>& args)
45     {
46         num n;
47         if (isNum(args[0], n)) {
48             return tree(atan(double(n)));
49         } else {
50             return tree(symbol(), args[0]);
51         }
52     }
53 
generateCode(CodeContainer * container,const list<ValueInst * > & args,::Type result,vector<::Type> const & types)54     virtual ValueInst* generateCode(CodeContainer* container, const list<ValueInst*>& args, ::Type result,
55                                     vector<::Type> const& types)
56     {
57         faustassert(args.size() == arity());
58         faustassert(types.size() == arity());
59 
60         Typed::VarType         result_type;
61         vector<Typed::VarType> arg_types;
62         list<ValueInst*>       casted_args;
63         prepareTypeArgsResult(result, args, types, result_type, arg_types, casted_args);
64 
65         return container->pushFunction(subst("atan$0", isuffix()), result_type, arg_types, casted_args);
66     }
67 
old_generateCode(Klass * klass,const vector<string> & args,const vector<::Type> & types)68     virtual string old_generateCode(Klass* klass, const vector<string>& args, const vector<::Type>& types)
69     {
70         faustassert(args.size() == arity());
71         faustassert(types.size() == arity());
72 
73         return subst("atan$1($0)", args[0], isuffix());
74     }
75 
generateLateq(Lateq * lateq,const vector<string> & args,const vector<::Type> & types)76     virtual string generateLateq(Lateq* lateq, const vector<string>& args, const vector<::Type>& types)
77     {
78         faustassert(args.size() == arity());
79         faustassert(types.size() == arity());
80 
81         return subst("\\arctan\\left($0\\right)", args[0]);
82     }
83 };
84