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()}; } } }
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)); }
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)); }
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)); }
void checkDivideByZero(Executer &executer, T rhs) { if (rhs == 0) { throw RunError {"divide by zero", executer.currentOffset()}; } }