Esempio n. 1
0
inline void validatePowerResult(double x, double result, Executer &executer)
{
    if (std::isnan(result)) {
        throw RunError {"domain error (non-integer exponent)", executer.currentOffset()};
    } else if (result == HUGE_VAL) {
        if (x == 0) {
            throw RunError {"divide by zero", executer.currentOffset()};
        } else {
            throw RunError {"overflow", executer.currentOffset()};
        }
    }
}
Esempio n. 2
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));
}
Esempio n. 3
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));
}
Esempio n. 4
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));
}
Esempio n. 5
0
void checkDivideByZero(Executer &executer, T rhs)
{
    if (rhs == 0) {
        throw RunError {"divide by zero", executer.currentOffset()};
    }
}