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 Atan2Prim : public xtended { 29 public: Atan2Prim()30 Atan2Prim() : xtended("atan2") {} 31 arity()32 virtual unsigned int arity() { return 2; } 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() == 2); 39 return floatCast(args[0] | args[1]); 40 } 41 infereSigOrder(const vector<int> & args)42 virtual int infereSigOrder(const vector<int>& args) { return max(args[0], args[1]); } 43 computeSigOutput(const vector<Tree> & args)44 virtual Tree computeSigOutput(const vector<Tree>& args) 45 { 46 faustassert(args.size() == 2); 47 num n, m; 48 if (isNum(args[0], n) && isNum(args[1], m)) { 49 return tree(atan2(double(n), double(m))); 50 } else { 51 return tree(symbol(), args[0], args[1]); 52 } 53 } 54 generateCode(CodeContainer * container,const list<ValueInst * > & args,::Type result,vector<::Type> const & types)55 virtual ValueInst* generateCode(CodeContainer* container, const list<ValueInst*>& args, ::Type result, 56 vector<::Type> const& types) 57 { 58 faustassert(args.size() == arity()); 59 faustassert(types.size() == arity()); 60 61 Typed::VarType result_type; 62 vector<Typed::VarType> arg_types; 63 list<ValueInst*> casted_args; 64 prepareTypeArgsResult(result, args, types, result_type, arg_types, casted_args); 65 66 return container->pushFunction(subst("atan2$0", isuffix()), result_type, arg_types, casted_args); 67 } 68 old_generateCode(Klass * klass,const vector<string> & args,const vector<Type> & types)69 virtual string old_generateCode(Klass* klass, const vector<string>& args, const vector<Type>& types) 70 { 71 faustassert(args.size() == arity()); 72 faustassert(types.size() == arity()); 73 74 return subst("atan2$2($0,$1)", args[0], args[1], isuffix()); 75 } 76 generateLateq(Lateq * lateq,const vector<string> & args,const vector<::Type> & types)77 virtual string generateLateq(Lateq* lateq, const vector<string>& args, const vector<::Type>& types) 78 { 79 faustassert(args.size() == arity()); 80 faustassert(types.size() == arity()); 81 82 return subst("\\arctan\\frac{$0}{$1}", args[0], args[1]); 83 } 84 }; 85