Esempio n. 1
0
Operator* Power::Simplified(
    Context* nctx,
    TypeCorrespondanceTable& table )
{
    Operator* sf = mySubOps[0]->Simplified(nctx, table);
    Operator* ss = mySubOps[1]->Simplified(nctx, table);
    
    if( sf->IsConstant() && ss->IsConstant() )
    {
        Constant* csf = reinterpret_cast<Constant*>(sf);
        Constant* css = reinterpret_cast<Constant*>(ss);
        
        return new Constant( nctx, std::pow(csf->GetValue(), css->GetValue() ) );
    }
    else if( ss->IsNull() )
        return new Constant( nctx, 1.0 );
    else if( ss->IsOne() )
        return sf;
    else
        return new Power( nctx, sf, ss );
}
Esempio n. 2
0
Operator* Division::Simplified(
    Context* nctx,
    TypeCorrespondanceTable& table )
{
    Operator* fp = mySubOps[0]->Simplified(nctx, table);
    Operator* fs = mySubOps[1]->Simplified(nctx, table);
    
    if( fp->IsNull() )
        return new Constant( nctx, 0.0, table[GetType()] );
    else if( fp->IsOne() )
        return new Inverse( nctx, fs );
    else if( fp->IsConstant() && fs->IsConstant() )
    {
        Constant* cfp = reinterpret_cast<Constant*>(fp);
        Constant* cfs = reinterpret_cast<Constant*>(fs);
        
        return new Constant( nctx, cfp->GetValue() / cfs->GetValue(), table[GetType()] );
    }
    else
        return new Division( nctx, fp, fs );
}