Details

Type: Subtask

Status: Closed

Priority: Minor

Resolution: Fixed

Affects Version/s: 1.8

Fix Version/s: None

Component/s: Questions

Labels:None

Affected Branches:MOODLE_18_STABLE
Description
When the answer is a small number i.e 1e19 as the charge of the electron the range of the allowed answer can extend to negative value given the fact that the code of add + a small number
line 355 of numerical/questiontype.php in the function get_tolerance_interval(&$answer) {
// We need to add a tiny fraction depending on the set precision to make the
// comparison work correctly. Otherwise seemingly equal values can yield
// false. (fixes bug #3225)
$tolerance = (float)$answer>tolerance + ("1.0e".ini_get('precision'));
This is to remediate for the 0.000000001 or .999999999 possible output of real number functions.
So if the user put an answer like 1.6e5 php code could sometimes see it 0.0000159999999 or 0.00001600000001
for small answer values the tiny fraction should be calcualted as a fraction of the number and not an absolute value
actually ("1.0e".ini_get('precision')); can gives something like 1e13 for a precision of 8 .
After completing tests, a working solution will be proposed soon
Gliffy Diagrams
Issue Links
 is duplicated by

MDL12375 Improving the grading of calculated question when there numbers are near the testing limit
 Closed
Activity
 All
 Comments
 Work Log
 History
 Activity
 Links Hierarchy
Modifying the line 360 and followings of numerical/questiontype.php to
{ $tolerance = 0.01* abs((float)$answer>answer) ; //arbitrary factor 1.01 }switch ($answer>tolerancetype) {
case '1': case 'relative':
/// Recalculate the tolerance and fall through
/// to the nominal case:
$tolerance = $answer>answer * $tolerance;
// 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 )
else if ((float)$answer>tolerance != 0.0 && abs((float)$answer>tolerance) < abs((float)$answer>answer) && abs((float)$answer>answer) <= $tolerance)
{ $tolerance = 1.01 * abs((float) $answer>tolerance) ;//arbitrary factor 1.01 }$max = $answer>answer + $tolerance;
$min = $answer>answer  $tolerance;
break;
solve the problem
More complete report on testing done will follow on moodle docs and or quiz forum.