Arithmetic Operators include +,-, *,/, and %.
Arithmetic Operators
File: OperatorMathematic. js
Function OperatorMathematic () {<br/> this. deriveFrom (new OperatorBinaryBase (); <br/> this. set_ClassName ("OperatorMathematic"); <br/> this. set_Sign ("undefined"); <br/>}; </p> <p> function OperatorAdd () {<br/> this. deriveFrom (new OperatorMathematic (); <br/> this. set_ClassName ("OperatorAdd"); <br/> this. set_Sign ("+"); <br/>}; </p> <p> OperatorAdd. prototype. evaluate = function (operands) {<br/> var values = this. _ getTwoNumberOperands (operands); </p> <p> return new OperandNumber (values [0]. get_Value () + values [1]. get_Value (); <br/>}; </p> <p> function OperatorSubtract () {<br/> this. deriveFrom (new OperatorMathematic (); <br/> this. set_ClassName ("OperatorSubtract"); <br/> this. set_Sign ("-"); <br/>}; </p> <p> OperatorSubtract. prototype. evaluate = function (operands) {<br/> var values = this. _ getTwoNumberOperands (operands); </p> <p> return new OperandNumber (values [0]. get_Value ()-values [1]. get_Value (); <br/>}; </p> <p> function OperatorMultiply () {<br/> this. deriveFrom (new OperatorMathematic (); <br/> this. set_ClassName ("OperatorMultiply"); <br/> this. set_Sign ("*"); <br/>}; </p> <p> OperatorMultiply. prototype. evaluate = function (operands) {<br/> var values = this. _ getTwoNumberOperands (operands); </p> <p> return new OperandNumber (values [0]. get_Value () * values [1]. get_Value (); <br/>}; </p> <p> function OperatorDivide () {<br/> this. deriveFrom (new OperatorMathematic (); <br/> this. set_ClassName ("OperatorDivide"); <br/> this. set_Sign ("/"); <br/>}; </p> <p> OperatorDivide. prototype. evaluate = function (operands) {<br/> var values = this. _ getTwoNumberOperands (operands); </p> <p> return new OperandNumber (values [0]. get_Value ()/values [1]. get_Value (); <br/>}; </p> <p> function OperatorModule () {<br/> this. deriveFrom (new OperatorMathematic (); <br/> this. set_ClassName ("OperatorModule"); <br/> this. set_Sign ("%"); <br/>}; </p> <p> OperatorModule. prototype. evaluate = function (operands) {<br/> var values = this. _ getTwoNumberOperands (operands); </p> <p> if (values [1]. get_Value () = 0) <br/> throw new Exception (this, "Evaluate", "Divide by zero "); </p> <p> return new OperandNumber (values [0]. get_Value () % values [1]. get_Value (); <br/> };