Permalink
Browse files

Merge branch 'MDL-36025-negative-zero-MOODLE_22_STABLE' of git://gith…

…ub.com/mpetrowi/moodle into MOODLE_22_STABLE
  • Loading branch information...
2 parents 5a0ac06 + 4befe7f commit 12a90d7af0047d36bcd1443b9122ab29f26f2cfa @danpoltawski danpoltawski committed Dec 11, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 question/type/calculated/questiontype.php
@@ -1224,7 +1224,7 @@ public function substitute_variables($str, $dataset) {
echo $OUTPUT->notification(get_string('notvalidnumber', 'qtype_calculated', $a));
$val = 1.0;
}
- if ($val < 0) {
+ if ($val <= 0) { // MDL-36025 Use parentheses for "-0"
$str = str_replace('{'.$name.'}', '('.$val.')', $str);
} else {
$str = str_replace('{'.$name.'}', $val, $str);
@@ -1252,6 +1252,7 @@ public function substitute_variables_and_eval($str, $dataset) {
} else if ($formula === '*') {
$str = '*';
} else {
+ $str = null;
eval('$str = '.$formula.';');
}
return $str;
@@ -1866,6 +1867,11 @@ function qtype_calculated_calculate_answer($formula, $individualdata,
// Exchange formula variables with the correct values...
$answer = question_bank::get_qtype('calculated')->substitute_variables_and_eval(
$formula, $individualdata);
+ if (!is_numeric($answer)) {
+ // Something went wrong, so just return NaN.
+ $calculated->answer = NAN;
+ return $calculated;
+ }
if ('1' == $answerformat) { /* Answer is to have $answerlength decimals */
/*** Adjust to the correct number of decimals ***/
if (stripos($answer, 'e')>0) {

0 comments on commit 12a90d7

Please sign in to comment.