Reworked evaluation to use internal type instead of boost::any
This commit is contained in:
50
src/Evaluator/EvalValues/NumericEvalValue.cpp
Normal file
50
src/Evaluator/EvalValues/NumericEvalValue.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
#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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user