/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package expressiontree.operators.unary;

import expressiontree.ExpressionTreeElement;
import expressiontree.operators.UnaryOperator;
import expressiontree.operands.NumberType;
import expressiontree.operators.IncompatibleNumberFormatException;
import org.apfloat.ApfloatMath;

/**
 * A e^x típusú operátorok osztálya.
 * @author Esta
 */
public class Exponent extends UnaryOperator {

    @Override
    public ExpressionTreeElement getValue() throws IncompatibleNumberFormatException {
        ExpressionTreeElement op1 = this.operands.get(0).getValue();
        if (op1 instanceof NumberType) {
            //csak akkor lehet számolni, ha számot találtunk
            NumberType n = (NumberType) op1;
            NumberType retValue = new NumberType(this.precision,false);
            retValue.setValue(ApfloatMath.exp(n.getNumericValue()));
            return retValue;
        } else { //mátrix >> exception
            throw new IncompatibleNumberFormatException("ERROR_EXP");
        }
    }

    @Override
    public String toText(boolean b) {
        if (b) {
            return "exp()";
        } else {
            return "exp ";
        }
    }

    @Override
    public String getLocalizedName() {
        return java.util.ResourceBundle.getBundle("languages/operators").getString("EXP");
    }
}
