⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 muldivoperatortoken.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.core.tokens;

import jmathlib.core.interpreter.*;
import jmathlib.core.tokens.numbertokens.DoubleNumberToken;


/**Class representing multiplicaton and division operations within an expression*/
public class MulDivOperatorToken extends BinaryOperatorToken
{
    /**constant values*/
    //static public final MulDivOperatorToken divide   = new MulDivOperatorToken('/');
    //static public final MulDivOperatorToken multiply = new MulDivOperatorToken('*');


    /**Constructor taking the operator and priority
    @param _operator = the actual operator	  */
    public MulDivOperatorToken (char _operator)
    {
    	/**call the super constructor, type defaults to ttoperator and operands to 2*/
        super(_operator, MULDIV_PRIORITY);
    }

    /**evaluate the operator
    @param operands = the operators operands
    @return the result as an OperandToken*/
    public OperandToken evaluate(Token[] operands)
    {
        OperandToken result = null;

        OperandToken left = ((OperandToken)operands[0]);       
        if(left == null)
        	left = new DoubleNumberToken(0);
        	
        OperandToken right = ((OperandToken)operands[1]);
        if(right == null)
        	right = new DoubleNumberToken(0);

        OperandToken[] ops = {left, right}; //castOperands(left, right);			
			
	    //now evaluate op on left and right        
	    if(value == '*')
	    {
	        result = ops[0].multiply(ops[1]);
	    }
	    else if (value == '/')
	    {
	        result = ops[0].divide(ops[1]);
	    }
	    else if (value == 'm')
	    {
    		//scalar multiplication
    		result = ops[0].scalarMultiply(ops[1]);
	    }	
	    else if (value == 'd')
	    {
    		//scalar division
    		result = ops[0].scalarDivide(ops[1]);
	    }
        else if (value == 'L')
        {
            //left division
            result = ops[0].leftDivide(ops[1]);
        }
        else if (value == 'l')
        {
            //scalar left division
            result = ops[0].scalarLeftDivide(ops[1]);
        }
        else
            Errors.throwMathLibException("MulDiv: do not know operator");
        
        if(result == null)
        {
            //return origional expression
            result = new Expression(this, left, right);
        }
        
        return result;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -