/*
 * The MIT License
 *
 * Copyright 2016 Maxim Krivchun.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package cexpr;

import java.util.HashMap;

/**
 *
 * @author Maxim Krivchun
 */
public class Functions extends HashMap<String, Functions.function> {

    public interface function {

        public Complex eval(Complex arg);
    }

    public Functions() {
        put("sin", new function() {
            @Override
            public Complex eval(Complex arg) {
                return ComplexUtils.sin(arg);
            }

        });
        put("cos", new function() {
            @Override
            public Complex eval(Complex arg) {
                return ComplexUtils.cos(arg);
            }

        });
        put("tan", new function() {
            @Override
            public Complex eval(Complex arg) {
                return ComplexUtils.tan(arg);
            }

        });
        put("ctan", new function() {
            @Override
            public Complex eval(Complex arg) {
                return ComplexUtils.ctan(arg);
            }

        });
        put("re", new function() {
            @Override
            public Complex eval(Complex arg) {
                return new Complex(arg.re, 0);
            }

        });
        put("im", new function() {
            @Override
            public Complex eval(Complex arg) {
                return new Complex(arg.im, 0);
            }

        });
        put("abs", new function() {
            @Override
            public Complex eval(Complex arg) {
                return new Complex(ComplexUtils.abs(arg), 0);
            }
        });
    }

}

@@ -2647,21 +2647,2267 @@
         %7D);%0A
+        put(%22con%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.conjugate(arg);%0A            %7D%0A        %7D);%0A        put(%22asin%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.asin(arg);%0A            %7D%0A        %7D);%0A        put(%22acos%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.acos(arg);%0A            %7D%0A        %7D);%0A        put(%22sqrt%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.sqrt(arg);%0A            %7D%0A        %7D);%0A        put(%22atan%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.atan(arg);%0A            %7D%0A        %7D);%0A        put(%22exp%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.exp(arg);%0A            %7D%0A        %7D);%0A        put(%22ln%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.ln(arg);%0A            %7D%0A        %7D);%0A        put(%22log10%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.log10(arg);%0A            %7D%0A        %7D);%0A        put(%22arg%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return new Complex(ComplexUtils.arg(arg), 0);%0A            %7D%0A        %7D);%0A        put(%22rnd%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                Complex rnd = ComplexUtils.random(arg);%0A                return new Complex(rnd.re * arg.re, rnd.im * arg.im);%0A            %7D%0A        %7D);%0A        put(%22round%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return ComplexUtils.round(arg);%0A            %7D%0A        %7D);%0A        put(%22inv%22, new function() %7B%0A            @Override%0A            public Complex eval(Complex arg) %7B%0A                return new Complex(arg.im, arg.re);%0A            %7D%0A        %7D);%0A
     %7D%0A%0A%7D%0A

add more functions