Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-15358

Calculated question is not calculating correct when there is a double negative

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: None
    • Component/s: Quiz
    • Labels:
      None
    • Environment:
      Linux
      Apache
      atabase mysql versie 3.23 is vereist en je gebruikt nu versie 4.1.20 OK
      php versie 4.1.0 is vereist en je gebruikt nu versie 4.3.9 OK

      Mysql
    • Affected Branches:
      MOODLE_16_STABLE

      Description

      When calculated questions are used and a variable is negative (In this case

      {c} then the outcome is wrong, in our case 0

      70/10- 3= 7-3=7+3=10
      {a} / {b} - {c}

      = ?

      The result becomes 0

      All positive variables calculate correct

      When brackets are place around the (

      {a}

      /

      {b}

      ) -

      {c}

      = ?

      the calculation is correct

        Gliffy Diagrams

          Activity

          Hide
          ppichet Pierre Pichet added a comment -

          When brackets are place around the negative value

          {a} / {b} -( {c}) = ?

          the calculation is correct.
          One way to correct is to replace each variable in the math function by its value enclosed in brackets so{a}

          /

          {b}

          -

          {c}

          = ?
          will give
          (70)/(10)-( -3).
          But the the equation display could contain numerous () and the user could have problem to understand it.
          On the other end, negative values seems to be rarely used as this problem has not been reported before (I think).
          I prefer to add a notice on the docs about using

          {x}

          parameters with negative values and not change the code.

          Show
          ppichet Pierre Pichet added a comment - When brackets are place around the negative value {a} / {b} -( {c}) = ? the calculation is correct. One way to correct is to replace each variable in the math function by its value enclosed in brackets so{a} / {b} - {c} = ? will give (70)/(10)-( -3). But the the equation display could contain numerous () and the user could have problem to understand it. On the other end, negative values seems to be rarely used as this problem has not been reported before (I think). I prefer to add a notice on the docs about using {x} parameters with negative values and not change the code.
          Hide
          ppichet Pierre Pichet added a comment -

          On further thinking, the () will be added automatically when the value is negative
          So

          {a}

          /

          {b}

          -

          {c} = ?
          will give with {c}

          value = -3
          70/10-( -3)
          and with

          {c}

          value = 5
          70/10-5

          Show
          ppichet Pierre Pichet added a comment - On further thinking, the () will be added automatically when the value is negative So {a} / {b} - {c} = ? will give with {c} value = -3 70/10-( -3) and with {c} value = 5 70/10-5
          Hide
          ppichet Pierre Pichet added a comment -

          Tim
          I CVS down to 1.7 and 1.6
          However there was a little mistake when doing 1.6 and 17 so I CVS a new versions .1.2.5 that I tag as MERGED before giving the MERGED tag to 1.2.4 which remains in STABLE.
          Is there any problem?

          Show
          ppichet Pierre Pichet added a comment - Tim I CVS down to 1.7 and 1.6 However there was a little mistake when doing 1.6 and 17 so I CVS a new versions .1.2.5 that I tag as MERGED before giving the MERGED tag to 1.2.4 which remains in STABLE. Is there any problem?
          Hide
          timhunt Tim Hunt added a comment -

          No problem with the merge tags on the 1.6 and 1.7 branches.

          I think the MOODLE_19_MERGED tag on question/type/calculated/questiontype.php needs to be updated, and the MOODLE_18_MERGED tag on question/type/datasetdependent/abstractqtype.php

          Show
          timhunt Tim Hunt added a comment - No problem with the merge tags on the 1.6 and 1.7 branches. I think the MOODLE_19_MERGED tag on question/type/calculated/questiontype.php needs to be updated, and the MOODLE_18_MERGED tag on question/type/datasetdependent/abstractqtype.php
          Hide
          ppichet Pierre Pichet added a comment -

          I think the MOODLE_19_MERGED tag on question/type/calculated/questiontype.php needs to be updated, and the MOODLE_18_MERGED tag on question/type/datasetdependent/abstractqtype.php
          Done
          thanks for checking

          Show
          ppichet Pierre Pichet added a comment - I think the MOODLE_19_MERGED tag on question/type/calculated/questiontype.php needs to be updated, and the MOODLE_18_MERGED tag on question/type/datasetdependent/abstractqtype.php Done thanks for checking

            People

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

              Dates

              • Created:
                Updated:
                Resolved: