Example #1
0
inline void executeSgn(Executer &executer)
{
    auto argument = executer.top<T>();
    if (argument > T{0}) {
        executer.setTop(T{1});
    } else if (argument < 0.0) {
        executer.setTop(T{-1});
    } else {
        executer.setTop(T{0});
    }
}
Example #2
0
void executeExponentialIntInt(Executer &executer)
{
    auto y = executer.topInt();
    executer.pop();
    auto x = executer.topInt();
    executer.setTop(PowerIntInt{executer, x, y}());
}
Example #3
0
void executeAbsDbl(Executer &executer)
{
    auto argument = executer.topDbl();
    if (argument < 0) {
        executer.setTop(-argument);
    }
}
Example #4
0
void executeDivideDblInt(Executer &executer)
{
    auto rhs = static_cast<double>(popIntegerDivisor(executer));
    auto lhs = executer.topDbl();
    auto result = lhs / rhs;
    executer.setTop(result);
}
Example #5
0
void executeCatStrStr(Executer &executer)
{
    auto rhs = executer.topStr();
    executer.pop();

    executer.setTop(*executer.topStr());
    *executer.topTmpStr() += *rhs;
}
Example #6
0
void executeSqr(Executer &executer)
{
    auto argument = executer.topDbl();
    if (argument < 0) {
        throw RunError {"square root of negative number", executer.currentOffset()};
    }
    executer.setTop(std::sqrt(argument));
}
Example #7
0
void executeLog(Executer &executer)
{
    auto argument = executer.topDbl();
    if (argument <= 0) {
        throw RunError {"logarithm of non-positive number", executer.currentOffset()};
    }
    executer.setTop(std::log(argument));
}
Example #8
0
void executeSubtractDblDbl(Executer &executer)
{
    auto rhs = executer.topDbl();
    executer.pop();
    auto result = executer.topDbl() - rhs;
    checkDoubleOverflow(executer, result);
    executer.setTop(result);
}
Example #9
0
void executeAbsInt(Executer &executer)
{
    auto argument = executer.topInt();
    if (argument < 0) {
        checkNegativeIntegerOverflow(executer, argument);
        executer.setTop(-argument);
    }
}
Example #10
0
void executeRndInt(Executer &executer)
{
    auto argument = executer.topInt();
    if (argument <= 0) {
        throw RunError {"random function on zero or negative number", executer.currentOffset()};
    }
    executer.setTop(executer.getRandomNumber(argument));
}
Example #11
0
void executeCatStrTmp(Executer &executer)
{
    auto rhs_result = executer.topTmpStr();
    executer.pop();

    auto lhs_rhs = std::string{*executer.topStr()};
    std::swap(lhs_rhs, *rhs_result);

    executer.setTop(rhs_result);
    *executer.topTmpStr() += lhs_rhs;
}
Example #12
0
void executeSubtractDblInt(Executer &executer)
{
    auto rhs = executer.topIntAsDbl();
    executer.pop();
    executer.setTop(executer.topDbl() - rhs);
}
Example #13
0
void executeFrac(Executer &executer)
{
    auto argument = executer.topDbl();
    executer.setTop(argument - std::trunc(argument));
}
Example #14
0
void executeExp(Executer &executer)
{
    auto result = std::exp(executer.topDbl());
    checkForOverflow(executer, result);
    executer.setTop(result);
}
Example #15
0
void executeCvtDbl(Executer &executer)
{
    executer.setTop(executer.topIntAsDbl());
}
Example #16
0
void executeAtn(Executer &executer)
{
    executer.setTop(std::atan(executer.topDbl()));
}
Example #17
0
inline void calculatePowerDblDbl(Executer &executer, double x, double y)
{
    auto result = std::pow(x, y);
    validatePowerResult(x, result, executer);
    executer.setTop(result);
}
Example #18
0
void executeSin(Executer &executer)
{
    executer.setTop(std::sin(executer.topDbl()));
}
Example #19
0
void executeModuloIntInt(Executer &executer)
{
    auto rhs = popIntegerDivisor(executer);
    executer.setTop(executer.topInt() % rhs);
}
Example #20
0
void executeModuloDblInt(Executer &executer)
{
    auto rhs = static_cast<double>(popIntegerDivisor(executer));
    auto lhs = executer.topDbl();
    executer.setTop(std::fmod(lhs, rhs));
}
Example #21
0
void executeAddDblInt(Executer &executer)
{
    auto rhs = executer.topIntAsDbl();
    executer.pop();
    executer.setTop(executer.topDbl() + rhs);
}
Example #22
0
void executeModuloIntDbl(Executer &executer)
{
    auto rhs = popDoubleDivisor(executer);
    auto lhs = executer.topIntAsDbl();
    executer.setTop(std::fmod(lhs, rhs));
}
Example #23
0
void executeInt(Executer &executer)
{
    executer.setTop(std::floor(executer.topDbl()));
}
Example #24
0
void executeXor(Executer &executer)
{
    auto rhs = executer.topInt();
    executer.pop();
    executer.setTop(executer.topInt() ^ rhs);
}
Example #25
0
void executeAnd(Executer &executer)
{
    auto rhs = executer.topInt();
    executer.pop();
    executer.setTop(executer.topInt() & rhs);
}
Example #26
0
void executeNot(Executer &executer)
{
    executer.setTop(~executer.topInt());
}
Example #27
0
void executeEqv(Executer &executer)
{
    auto rhs = executer.topInt();
    executer.pop();
    executer.setTop(~(executer.topInt() ^ rhs));
}
Example #28
0
void executeCos(Executer &executer)
{
    executer.setTop(std::cos(executer.topDbl()));
}
Example #29
0
void executeFix(Executer &executer)
{
    executer.setTop(std::trunc(executer.topDbl()));
}
Example #30
0
void executeImp(Executer &executer)
{
    auto rhs = executer.topInt();
    executer.pop();
    executer.setTop(~executer.topInt() | rhs);
}