All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codetaco.math.impl.function.FuncCos Maven / Gradle / Ivy

package com.codetaco.math.impl.function;

import com.codetaco.math.impl.EquImpl;
import com.codetaco.math.impl.Function;
import com.codetaco.math.impl.ValueStack;
import com.codetaco.math.impl.token.TokVariable;

import java.text.ParseException;

public class FuncCos extends Function {
    public FuncCos(EquImpl equ) {
        super(equ);
    }

    public FuncCos(EquImpl equ, TokVariable var) {
        super(equ, var);
    }

    @Override
    public void resolve(final ValueStack values) throws Exception {
        if (values.size() < 1) {
            throw new Exception("missing operands for " + toString());
        }
        try {
            final double degrees = values.popDouble();
            final double rads = degrees * (Math.PI / 180);
            values.push(new Double(Math.cos(rads)));
        } catch (final ParseException e) {
            e.fillInStackTrace();
            throw new Exception(toString() + "; " + e.getMessage(), e);
        }
    }

    @Override
    public String toString() {
        return "function(cos)";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy