Moodle
  1. Moodle
  2. MDL-27139

mathslib used by gradebook incorrectly evaluating expressions

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.8
    • Fix Version/s: 2.1
    • Component/s: Gradebook, Libraries
    • Labels:
      None
    • Difficulty:
      Moderate
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE
    • Rank:
      16900

      Description

      There are errors in maths expression evaluation by mathslib as used by gradebook.

      'pi() * 5', or pi() followed by any over operation generates an error when trying to convert to postfix. pi is the only user defined function with no operands, seems to be an error in the interpreter here.

      Also '-8*(5/2)^2' is evaluated as -18 instead of -50.

        Issue Links

          Activity

          Hide
          Jamie Pratt added a comment -

          Oops. One of the errors I was seeing in unit tests was due to using the wrong operator to compare the result of the expression too. I was using the php XOR operator '^' which I thought was the power operator in my php expression to compare the result too, so the error there was in my PHP not the mathslib.

          Still looking at why pi() followed by another operation does not work in expressions.

          Show
          Jamie Pratt added a comment - Oops. One of the errors I was seeing in unit tests was due to using the wrong operator to compare the result of the expression too. I was using the php XOR operator '^' which I thought was the power operator in my php expression to compare the result too, so the error there was in my PHP not the mathslib. Still looking at why pi() followed by another operation does not work in expressions.
          Hide
          Jamie Pratt added a comment - - edited

          Hi,

          On this branch https://github.com/jamiepratt/Moodle-Question-Engine-2/compare/wip-evalmathclass there are three commits :

          I have a fix for the problem with pi().
          Also added some unit tests to test some more complex expressions in mathslib.
          Added switches to EvalMath to control whether mathematical constants are allowed and whether implicit multiplication is allowed.

          Jamie

          Show
          Jamie Pratt added a comment - - edited Hi, On this branch https://github.com/jamiepratt/Moodle-Question-Engine-2/compare/wip-evalmathclass there are three commits : I have a fix for the problem with pi(). Also added some unit tests to test some more complex expressions in mathslib. Added switches to EvalMath to control whether mathematical constants are allowed and whether implicit multiplication is allowed. Jamie
          Hide
          Jamie Pratt added a comment -
          Show
          Jamie Pratt added a comment - Added another commit to this branch https://github.com/jamiepratt/Moodle-Question-Engine-2/compare/wip-evalmathclass to address MDL-27162
          Hide
          Tim Hunt added a comment -

          I will be sumitting this for integration as part of a branch with MDL-27149

          Show
          Tim Hunt added a comment - I will be sumitting this for integration as part of a branch with MDL-27149
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Delegated testing to MDL-27149

          Show
          Eloy Lafuente (stronk7) added a comment - Delegated testing to MDL-27149
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Upstream-ized! Thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Upstream-ized! Thanks!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: