1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* Modification History
*
* 2001-February-11 Jason Rohrer
* Created.
*
* 2001-March-10 Jason Rohrer
* Added implementation of copy function.
*/
#ifndef POWER_EXPRESSION_INCLUDED
#define POWER_EXPRESSION_INCLUDED
#include "Expression.h"
#include "BinaryOperationExpression.h"
#include <math.h>
/**
* Expression implementation of a binary power operation.
* Raises the first argument to the power of the second,
* as in argA^argB.
*
* @author Jason Rohrer
*/
class PowerExpression : public BinaryOperationExpression {
public:
/**
* Constructs a binary power operation expression.
*
* Both arguments are destroyed when the class is destroyed.
*
* @param inArgumentA the first argument.
* @param inArgumentB the second argument.
*/
PowerExpression( Expression *inArgumentA,
Expression *inArgumentB );
/**
* A static version of getID().
*/
static long staticGetID();
// implements the Expression interface
virtual double evaluate();
virtual long getID();
virtual void print();
virtual Expression *copy();
protected:
static long mID;
};
// static init
long PowerExpression::mID = 4;
inline PowerExpression::PowerExpression( Expression *inArgumentA,
Expression *inArgumentB )
: BinaryOperationExpression( inArgumentA, inArgumentB ) {
}
inline double PowerExpression::evaluate() {
return pow( mArgumentA->evaluate(), mArgumentB->evaluate() );
}
inline long PowerExpression::getID() {
return mID;
}
inline long PowerExpression::staticGetID() {
return mID;
}
inline void PowerExpression::print() {
printf( "( " );
mArgumentA->print();
printf( " ^ " );
mArgumentB->print();
printf( " )" );
}
inline Expression *PowerExpression::copy() {
PowerExpression *copy =
new PowerExpression( mArgumentA->copy(),
mArgumentB->copy() );
return copy;
}
#endif
|