Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Minor 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 1e-19 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.6e-5 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 1e-13 for a precision of 8 .
      After completing tests, a working solution will be proposed soon

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            Pierre Pichet added a comment -

            Modifying the line 360 and followings of numerical/questiontype.php to
            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 )

            { $tolerance = 0.01* abs((float)$answer->answer) ; //arbitrary factor 1.01 }

            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.

            Show
            Pierre Pichet added a comment - Modifying the line 360 and followings of numerical/questiontype.php to 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 ) { $tolerance = 0.01* abs((float)$answer->answer) ; //arbitrary factor 1.01 } 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.
            Hide
            Pierre Pichet added a comment -

            the testing results can be seen in the quiz forum
            Small numerical answers i.e. 1e-18 are not graded correctly: testing a solution
            http://moodle.org/mod/forum/discuss.php?d=64596

            Show
            Pierre Pichet added a comment - the testing results can be seen in the quiz forum Small numerical answers i.e. 1e-18 are not graded correctly: testing a solution http://moodle.org/mod/forum/discuss.php?d=64596
            Hide
            Pierre Pichet added a comment -

            Other tests using the initial tiny fraction in the new code gave coherent values
            see
            http://moodle.org/mod/forum/discuss.php?d=64596#291061
            so the "final" proposition is the following
            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 )

            { $tolerance = (float) ("1.0e-".ini_get('precision')) * abs((float)$answer->answer) ; // tiny factor }

            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 factor }


            $max = $answer->answer + $tolerance;
            $min = $answer->answer - $tolerance;
            break;

            Show
            Pierre Pichet added a comment - Other tests using the initial tiny fraction in the new code gave coherent values see http://moodle.org/mod/forum/discuss.php?d=64596#291061 so the "final" proposition is the following 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 ) { $tolerance = (float) ("1.0e-".ini_get('precision')) * abs((float)$answer->answer) ; // tiny factor } 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 factor } $max = $answer->answer + $tolerance; $min = $answer->answer - $tolerance; break;
            Hide
            Pierre Pichet added a comment -

            This has been proted to the Moodle UQAM (1_6_3 version)
            http://moodle.uqam.ca and works correctly.
            The files are available on
            https://sourceforge.net/projects/moodleuqamchi

            Show
            Pierre Pichet added a comment - This has been proted to the Moodle UQAM (1_6_3 version) http://moodle.uqam.ca and works correctly. The files are available on https://sourceforge.net/projects/moodleuqamchi
            Hide
            Pierre Pichet added a comment -

            fix it using code already tested in Moodle UQAM, do CVS to 18_STABLE and merged TO HEAD.
            will merge to 16_stable and 17_stable and then close it

            Show
            Pierre Pichet added a comment - fix it using code already tested in Moodle UQAM, do CVS to 18_STABLE and merged TO HEAD. will merge to 16_stable and 17_stable and then close it

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: