Permalink
Browse files

Small numerical answers i.e. 1e-18 are not graded correctly MDL-8473 …

…merging from head
  • Loading branch information...
1 parent b7f1aee commit d8720eebc38bf6f04b7fed3362d9a9d5fedd6b3c pichetp committed May 17, 2007
Showing with 12 additions and 1 deletion.
  1. +12 −1 question/type/numerical/questiontype.php
@@ -356,9 +356,20 @@ function get_tolerance_interval(&$answer) {
/// Recalculate the tolerance and fall through
/// to the nominal case:
$tolerance = $answer->answer * $tolerance;
- // Falls through to the nominal case -
+ // Do not fall through to the nominal case because the tiny fraction is a factor of the answer
+ $tolerance = abs($tolerance); // important - otherwise min and max are swapped
+ $max = $answer->answer + $tolerance;
+ $min = $answer->answer - $tolerance;
+ break;
case '2': case 'nominal':
$tolerance = abs($tolerance); // important - otherwise min and max are swapped
+ // $answer->tolerance 0 or something else
+ if ((float)$answer->tolerance == 0.0 && abs((float)$answer->answer) <= $tolerance ){
+ $tolerance = (float) ("1.0e-".ini_get('precision')) * abs((float)$answer->answer) ; //tiny fraction
+ } else if ((float)$answer->tolerance != 0.0 && abs((float)$answer->tolerance) < abs((float)$answer->answer) && abs((float)$answer->answer) <= $tolerance){
+ $tolerance = (1+("1.0e-".ini_get('precision')) )* abs((float) $answer->tolerance) ;//tiny fraction
+ }
+
$max = $answer->answer + $tolerance;
$min = $answer->answer - $tolerance;
break;

0 comments on commit d8720ee

Please sign in to comment.