Fixed divide by 0 problem. This will slow down the division expression

slighly, but better slower than crashing the program.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@643 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-07-14 12:28:53 +00:00
parent 39b4f91c0d
commit c0924eaf4f
1 changed files with 5 additions and 4 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: DivExpression.hxx,v 1.1 2005-07-13 04:26:19 urchlay Exp $
// $Id: DivExpression.hxx,v 1.2 2005-07-14 12:28:53 stephena Exp $
//============================================================================
#ifndef DIV_EXPRESSION_HXX
@ -23,14 +23,15 @@
/**
@author B. Watson
@version $Id: DivExpression.hxx,v 1.1 2005-07-13 04:26:19 urchlay Exp $
@version $Id: DivExpression.hxx,v 1.2 2005-07-14 12:28:53 stephena Exp $
*/
class DivExpression : public Expression
{
public:
DivExpression(Expression *left, Expression *right);
int evaluate() { return myLHS->evaluate() / myRHS->evaluate(); } // FIXME: div by zero?
int evaluate() { int denom = myRHS->evaluate();
return denom == 0 ? 0 : myLHS->evaluate() / denom;
}
};
#endif