|
|
|
@ -4,22 +4,23 @@
|
|
|
|
|
ObjectBase* Arifm_Add(ObjectList* input) |
|
|
|
|
{ |
|
|
|
|
if(input->Size()!=2) return 0; |
|
|
|
|
std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); |
|
|
|
|
const ObjectBase *arg1=input->At(0),*arg2=input->At(1); |
|
|
|
|
std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); |
|
|
|
|
std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); |
|
|
|
|
|
|
|
|
|
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; |
|
|
|
|
|
|
|
|
|
// Integer arifmetic
|
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() + dynamic_cast<const ObjectInt*>(input->At(1))->Value()); |
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() + dynamic_cast<const ObjectInt*>(arg2)->Value()); |
|
|
|
|
|
|
|
|
|
// Real arifmetic
|
|
|
|
|
double r1,r2; |
|
|
|
|
|
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); |
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(arg1)->Value(); |
|
|
|
|
|
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); |
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(arg2)->Value(); |
|
|
|
|
|
|
|
|
|
return new ObjectReal(r1+r2); |
|
|
|
|
} |
|
|
|
@ -28,22 +29,23 @@ ObjectBase* Arifm_Add(ObjectList* input)
|
|
|
|
|
ObjectBase* Arifm_Sub(ObjectList* input) |
|
|
|
|
{ |
|
|
|
|
if(input->Size()!=2) return 0; |
|
|
|
|
std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); |
|
|
|
|
const ObjectBase *arg1=input->At(0),*arg2=input->At(1); |
|
|
|
|
std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); |
|
|
|
|
std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); |
|
|
|
|
|
|
|
|
|
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; |
|
|
|
|
|
|
|
|
|
// Integer arifmetic
|
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() - dynamic_cast<const ObjectInt*>(input->At(1))->Value()); |
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() - dynamic_cast<const ObjectInt*>(arg2)->Value()); |
|
|
|
|
|
|
|
|
|
// Real arifmetic
|
|
|
|
|
double r1,r2; |
|
|
|
|
|
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); |
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(arg1)->Value(); |
|
|
|
|
|
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); |
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(arg2)->Value(); |
|
|
|
|
|
|
|
|
|
return new ObjectReal(r1-r2); |
|
|
|
|
} |
|
|
|
@ -52,22 +54,23 @@ ObjectBase* Arifm_Sub(ObjectList* input)
|
|
|
|
|
ObjectBase* Arifm_Mul(ObjectList* input) |
|
|
|
|
{ |
|
|
|
|
if(input->Size()!=2) return 0; |
|
|
|
|
std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); |
|
|
|
|
const ObjectBase *arg1=input->At(0),*arg2=input->At(1); |
|
|
|
|
std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); |
|
|
|
|
std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); |
|
|
|
|
|
|
|
|
|
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; |
|
|
|
|
|
|
|
|
|
// Integer arifmetic
|
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() * dynamic_cast<const ObjectInt*>(input->At(1))->Value()); |
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() * dynamic_cast<const ObjectInt*>(arg2)->Value()); |
|
|
|
|
|
|
|
|
|
// Real arifmetic
|
|
|
|
|
double r1,r2; |
|
|
|
|
|
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); |
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(arg1)->Value(); |
|
|
|
|
|
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); |
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(arg2)->Value(); |
|
|
|
|
|
|
|
|
|
return new ObjectReal(r1*r2); |
|
|
|
|
} |
|
|
|
@ -76,22 +79,23 @@ ObjectBase* Arifm_Mul(ObjectList* input)
|
|
|
|
|
ObjectBase* Arifm_Div(ObjectList* input) |
|
|
|
|
{ |
|
|
|
|
if(input->Size()!=2) return 0; |
|
|
|
|
std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); |
|
|
|
|
const ObjectBase *arg1=input->At(0),*arg2=input->At(1); |
|
|
|
|
std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); |
|
|
|
|
std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); |
|
|
|
|
|
|
|
|
|
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; |
|
|
|
|
|
|
|
|
|
// Integer arifmetic
|
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() / dynamic_cast<const ObjectInt*>(input->At(1))->Value()); |
|
|
|
|
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() / dynamic_cast<const ObjectInt*>(arg2)->Value()); |
|
|
|
|
|
|
|
|
|
// Real arifmetic
|
|
|
|
|
double r1,r2; |
|
|
|
|
|
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); |
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(arg1)->Value(); |
|
|
|
|
|
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); |
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(arg2)->Value(); |
|
|
|
|
|
|
|
|
|
return new ObjectReal(r1/r2); |
|
|
|
|
} |
|
|
|
@ -100,7 +104,8 @@ ObjectBase* Arifm_Div(ObjectList* input)
|
|
|
|
|
ObjectBase* Arifm_Pow(ObjectList* input) |
|
|
|
|
{ |
|
|
|
|
if(input->Size()!=2) return 0; |
|
|
|
|
std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); |
|
|
|
|
const ObjectBase *arg1=input->At(0),*arg2=input->At(1); |
|
|
|
|
std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); |
|
|
|
|
std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); |
|
|
|
|
|
|
|
|
|
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; |
|
|
|
@ -108,11 +113,11 @@ ObjectBase* Arifm_Pow(ObjectList* input)
|
|
|
|
|
// Only real arifmetic
|
|
|
|
|
double r1,r2; |
|
|
|
|
|
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); |
|
|
|
|
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value(); |
|
|
|
|
else r1=dynamic_cast<const ObjectInt*>(arg1)->Value(); |
|
|
|
|
|
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); |
|
|
|
|
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value(); |
|
|
|
|
else r2=dynamic_cast<const ObjectInt*>(arg2)->Value(); |
|
|
|
|
|
|
|
|
|
return new ObjectReal(pow(r1,r2)); |
|
|
|
|
} |
|
|
|
@ -121,13 +126,14 @@ ObjectBase* Arifm_Pow(ObjectList* input)
|
|
|
|
|
ObjectBase* Arifm_Neg(ObjectList* input) |
|
|
|
|
{ |
|
|
|
|
if(input->Size()!=1) return 0; |
|
|
|
|
std::type_index t(typeid(*input->At(0))); |
|
|
|
|
const ObjectBase *arg=input->At(0); |
|
|
|
|
std::type_index t(typeid(*arg)); |
|
|
|
|
std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); |
|
|
|
|
|
|
|
|
|
// Integer arifmetic
|
|
|
|
|
if(t==ti) return new ObjectInt(-dynamic_cast<const ObjectInt*>(input->At(0))->Value()); |
|
|
|
|
if(t==ti) return new ObjectInt(-dynamic_cast<const ObjectInt*>(arg)->Value()); |
|
|
|
|
// Real arifmetic
|
|
|
|
|
if(t==tr) return new ObjectReal(-dynamic_cast<const ObjectReal*>(input->At(0))->Value()); |
|
|
|
|
if(t==tr) return new ObjectReal(-dynamic_cast<const ObjectReal*>(arg)->Value()); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -136,13 +142,14 @@ ObjectBase* Arifm_Neg(ObjectList* input)
|
|
|
|
|
ObjectBase* Arifm_Pos(ObjectList* input) |
|
|
|
|
{ |
|
|
|
|
if(input->Size()!=1) return 0; |
|
|
|
|
std::type_index t(typeid(*input->At(0))); |
|
|
|
|
const ObjectBase *arg=input->At(0); |
|
|
|
|
std::type_index t(typeid(*arg)); |
|
|
|
|
std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); |
|
|
|
|
|
|
|
|
|
// Integer arifmetic
|
|
|
|
|
if(t==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value()); |
|
|
|
|
if(t==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg)->Value()); |
|
|
|
|
// Real arifmetic
|
|
|
|
|
if(t==tr) return new ObjectReal(dynamic_cast<const ObjectReal*>(input->At(0))->Value()); |
|
|
|
|
if(t==tr) return new ObjectReal(dynamic_cast<const ObjectReal*>(arg)->Value()); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|