Commit eb61250e authored by Niels Slot's avatar Niels Slot

Add an error when the square root of a negative number is tried

parent 2c3c5194
......@@ -1453,6 +1453,11 @@ new_item()
if (!checkParameterQuantity(node, 1, 20000+Token::Sqrt*100+90)) return;
double val = node->child(0)->value()->number();
if(val<0) {
addError(i18n("Can't do a sqrt of a negative number"), *node->child(0)->token(), 0);
node->value()->setNumber(0);
return;
}
node->value()->setNumber(sqrt(val));
EOS
parse_item()
......
......@@ -1048,6 +1048,11 @@ void Executer::executeSqrt(TreeNode* node) {
if (!checkParameterQuantity(node, 1, 20000+Token::Sqrt*100+90)) return;
double val = node->child(0)->value()->number();
if(val<0) {
addError(i18n("Can't do a sqrt of a negative number"), *node->child(0)->token(), 0);
node->value()->setNumber(0);
return;
}
node->value()->setNumber(sqrt(val));
}
void Executer::executeRound(TreeNode* node) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment