Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ggrading small numbers MDL-8478 merge from 18_STABLE

  • Loading branch information...
commit bf18b2aa09504bfaa5f4ba0283def2834fff783a 1 parent db365a1
pichetp authored
Showing with 15 additions and 3 deletions.
  1. +15 −3 question/type/numerical/questiontype.php
View
18 question/type/numerical/questiontype.php
@@ -4,7 +4,7 @@
* @author Martin Dougiamas and many others. Tim Hunt.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package question
- *//** */
+ **/
require_once("$CFG->dirroot/question/type/shortanswer/questiontype.php");
@@ -351,13 +351,25 @@ 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;
- case '3': case 'geometric':
+ case '3': case 'geometric':
$quotient = 1 + abs($tolerance);
$max = $answer->answer * $quotient;
$min = $answer->answer / $quotient;
Please sign in to comment.
Something went wrong with that request. Please try again.