Element* Calculateur::mod() { if(typeid(*this->pileC->top()) == typeid(Expression)) { this->eval(); } if(typeid(*this->pileC->top()) == typeid(Complexe)) { qDebug()<<"on est en complexe"; throw std::logic_error( "mod : le premier parametre doit être une constante"); } if(typeid(*this->pileC->top()) != typeid(Entier)) { throw std::logic_error("Il faut que l'élément soit un entier"); } if(typeid(*this->pileC->top()) == typeid(Entier)) { qDebug()<<"on est en entier"; Entier* m = dynamic_cast<Entier*>(this->pileC->pop()); /*!< module */ qDebug()<<"l'entier est"<<m->toQString(); if(typeid(*this->pileC->top()) == typeid(Expression)) { qDebug()<<"on est en expression"; this->pileC->push(m); throw std::logic_error("Le deuxième élément est une expression"); } if(typeid(*this->pileC->top()) == typeid(Complexe)) { qDebug()<<"on est en complexe"; this->pileC->push(m); throw std::logic_error("Le deuxième élément est un complexe"); } if(typeid(*this->pileC->top()) != typeid(Entier)) { qDebug()<<"on est en non entier"; throw std::logic_error("Le deuxième élément n'est pas de type entier"); } if(typeid(*this->pileC->top()) == typeid(Entier)) { qDebug()<<"on est en entier"; Entier* e = dynamic_cast<Entier*>(this->pileC->pop()); qDebug()<<e->toQString(); Entier* tmp = new Entier(e->getXAsInt()%m->getXAsInt()); qDebug()<<tmp->toQString(); delete m; delete e; this->pileC->push(tmp); return tmp; } else { throw std::logic_error("Le deuxième élément n'est pas un élément valide"); } } else { throw std::logic_error("Le premier élément n'est pas un élément valide"); } }
Element* Calculateur::fact() { if(typeid(*this->pileC->top()) == typeid(Expression)) { throw std::logic_error("L'élément du haut de la pile est une expression"); } if(typeid(*this->pileC->top()) == typeid(Complexe)) { qDebug()<<"on est en complexe"; throw std::logic_error("La fonction factorielle ne s'applique pas au complexe"); } if(typeid(*this->pileC->top()) != typeid(Entier)) { qDebug()<<"on est en non entier"; throw std::logic_error("La fonction factorielle ne s'applique qu'au entier"); } if(typeid(*this->pileC->top()) == typeid(Entier)) { qDebug()<<"on est en entier"; Entier* m = dynamic_cast<Entier*>(this->pileC->pop()); /*!< module */ int a,f; for(a=1,f=1;a<m->getXAsInt()+1;f*=a,a++); this->push(new Entier(f)); delete m; } else { throw std::logic_error("L'élément du haut de la pile n'est pas un élement valide"); } }
Element* Calculateur::sum() { Entier* e = dynamic_cast<Entier*>(this->pop()); qDebug()<<"ici ça marche"; for(unsigned int i=0;i<e->getXAsInt()-1;i++) { this->addition(); } qDebug()<<this->getPile()->top()->toQString(); }
Element* Calculateur::mean() { Entier* e = dynamic_cast<Entier*>(this->pop()); unsigned int i; for(i=0;i<e->getXAsInt()-1;i++) { this->addition(); } Reel* div = new Reel(i+1); Element* sum = this->pop(); Element* res = this->cast(&(sum->operator /(*div))); delete div; delete sum; this->push(res); }
Element* Calculateur::pow() { if(typeid(*this->pileC->top()) == typeid(Expression)) { this->eval(); } if(typeid(*this->pileC->top()) == typeid(Complexe)) { throw std::logic_error("Le premier élément ne peut pas être un complexe"); } else if(typeid(*this->pileC->top())== typeid(Entier)) { Entier* e = dynamic_cast<Entier*>(this->pileC->pop()); if(typeid(*this->pileC->top()) == typeid(Expression)) { Element* tmp = this->eval(); } else if(typeid(*this->pileC->top())== typeid(Entier) || typeid(*this->pileC->top())== typeid(Rationnel)) { Constante* c = dynamic_cast<Constante*>(this->pileC->pop()); if(e->getXAsInt()>= 0) { Rationnel* tmp = new Rationnel(::pow(c->getXAsInt(),e->getXAsInt()),::pow(c->getYAsInt(),e->getXAsInt())); qDebug()<<tmp->toQString(); Element* res = this->cast(tmp); delete e; delete c; delete tmp; this->pileC->push(res); } else { Reel* tmp = new Reel(::pow(c->getXAsFloat()/c->getYAsFloat(),e->getXAsInt())); Element* res = this->cast(tmp); delete e; delete c; delete tmp; this->pileC->push(res); } } else if(typeid(*this->pileC->top()) == typeid(Reel)) { Constante* c = dynamic_cast<Constante*>(this->pileC->pop()); Reel* tmp = new Reel(::pow(c->getXAsFloat(),e->getXAsFloat())); Element* res = this->cast(tmp); delete e; delete c; delete tmp; this->pileC->push(res); } else { throw std::logic_error("L'élément n'est pas un type connu"); } } else if(typeid(*this->pileC->top()) == typeid(Reel) || typeid(*this->pileC->top()) == typeid(Rationnel)) { Constante* p = dynamic_cast<Constante*>(this->pileC->pop()); if((typeid(*this->pileC->top()) == typeid(Entier))||(typeid(*this->pileC->top()) == typeid(Rationnel)) || typeid(*this->pileC->top()) == typeid(Reel)) { Constante* c = dynamic_cast<Constante*>(this->pileC->pop()); Reel* tmp = new Reel(::pow(c->getXAsFloat()/c->getYAsFloat(),p->getXAsFloat()/p->getYAsFloat())); Element* res = this->cast(tmp); delete p; delete c; delete tmp; this->pileC->push(res); return res; } else { throw std::logic_error("Le deuxième élément n'est pas un type valide"); } } else { throw std::logic_error("Le premier élément n'est pas un élément valide"); } }