]> git.mjollnir.org Git - moodle.git/commitdiff
grading correctly small numbers MDL-8478 merge from 18_STABLE
authorpichetp <pichetp>
Fri, 2 Mar 2007 20:45:12 +0000 (20:45 +0000)
committerpichetp <pichetp>
Fri, 2 Mar 2007 20:45:12 +0000 (20:45 +0000)
question/type/numerical/questiontype.php

index 58ebac7fced0abaa777519cc673f402f21f3ccca..dd7864c05fe6deefc92460072ef9651a7c779d4a 100644 (file)
@@ -351,13 +351,24 @@ class question_numerical_qtype extends question_shortanswer_qtype {
                 /// 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;
-            case '3': case 'geometric':
+           case '3': case 'geometric':
                 $quotient = 1 + abs($tolerance);
                 $max = $answer->answer * $quotient;
                 $min = $answer->answer / $quotient;