51 lines
2.1 KiB
C++
51 lines
2.1 KiB
C++
|
|
||
|
#include "NumericEvalValue.hpp"
|
||
|
|
||
|
NumericEvalValue *NumericEvalValue::operator+(NumericEvalValue *b) {
|
||
|
if (this->IsFloat() && b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() + b->GetFloatValue());
|
||
|
} else if (this->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() + b->GetIntegerValue());
|
||
|
} else if (b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetIntegerValue() + b->GetFloatValue());
|
||
|
} else{
|
||
|
return new IntegerEvalValue(this->GetIntegerValue() + b->GetIntegerValue());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
NumericEvalValue *NumericEvalValue::operator-(NumericEvalValue *b) {
|
||
|
if (this->IsFloat() && b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() - b->GetFloatValue());
|
||
|
} else if (this->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() - b->GetIntegerValue());
|
||
|
} else if (b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetIntegerValue() - b->GetFloatValue());
|
||
|
} else{
|
||
|
return new IntegerEvalValue(this->GetIntegerValue() - b->GetIntegerValue());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
NumericEvalValue *NumericEvalValue::operator*(NumericEvalValue *b) {
|
||
|
if (this->IsFloat() && b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() * b->GetFloatValue());
|
||
|
} else if (this->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() * b->GetIntegerValue());
|
||
|
} else if (b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetIntegerValue() * b->GetFloatValue());
|
||
|
} else{
|
||
|
return new IntegerEvalValue(this->GetIntegerValue() * b->GetIntegerValue());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
NumericEvalValue *NumericEvalValue::operator/(NumericEvalValue *b) {
|
||
|
if (this->IsFloat() && b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() / b->GetFloatValue());
|
||
|
} else if (this->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetFloatValue() / b->GetIntegerValue());
|
||
|
} else if (b->IsFloat()){
|
||
|
return new FloatEvalValue(this->GetIntegerValue() / b->GetFloatValue());
|
||
|
} else{
|
||
|
return new IntegerEvalValue(this->GetIntegerValue() / b->GetIntegerValue());
|
||
|
}
|
||
|
}
|