Element* Calculateur::tanh() { if(typeid(*this->pileC->top()) == typeid(Expression)) { this->eval(); } if(typeid(*this->pileC->top()) == typeid(Complexe)) { // } if(isRadian()) { Constante* tmp = dynamic_cast<Constante*> (this->pileC->pop()); Reel* resu = new Reel(::tanh(tmp->getXAsFloat()/tmp->getYAsFloat())); delete tmp; this->pileC->push(resu); return resu; } else { Constante* tmp = dynamic_cast<Constante*> (this->pileC->pop()); Reel* resu = new Reel(::tanh((tmp->getXAsFloat()/tmp->getYAsFloat())*PI/180.0)); delete tmp; this->pileC->push(resu); return resu; } }
Element* Calculateur::inv() { 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)) { throw std::logic_error("L'inverse d'un complexe n'est pas une commande disponible"); } Constante* c = dynamic_cast<Constante *>(this->pileC->pop()); Element* res; if(typeid(*c)== typeid(Entier) || typeid(*c)== typeid(Rationnel)) { res = new Rationnel(c->getYAsInt(),c->getXAsInt()); } else { res = new Reel(1./c->getXAsFloat()); } delete c; this->pileC->push(res); return res; }
Element* Calculateur::log() { if(typeid(*this->pileC->top()) == typeid(Expression)) { this->eval(); } if(typeid(*this->pileC->top()) == typeid(Complexe)) { // } if(isRadian()) { Constante* tmp = dynamic_cast<Constante*> (this->pileC->pop()); if(tmp->getXAsFloat()<0 && tmp->getYAsFloat() <0) { //ERREUR return 0; } else { Reel* resu = new Reel(::log10(tmp->getXAsFloat()/tmp->getYAsFloat())); delete tmp; this->pileC->push(resu); return resu; } } else { Constante* tmp = dynamic_cast<Constante*> (this->pileC->pop()); if(tmp->getXAsFloat()<0 && tmp->getYAsFloat() <0) { //ERREUR return 0; } else { Reel* resu = new Reel(::log10((tmp->getXAsFloat()/tmp->getYAsFloat()))); delete tmp; this->pileC->push(resu); return resu; } } }
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"); } }