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

mathslib used by gradebook incorrectly evaluating expressions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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

      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.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              jamiesensei 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
              jamiesensei 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
              jamiesensei 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
              jamiesensei 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
              jamiesensei Jamie Pratt added a comment -
              Show
              jamiesensei 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
              timhunt Tim Hunt added a comment -

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

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

              Delegated testing to MDL-27149

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

              Upstream-ized! Thanks!

              Show
              stronk7 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:
                    Fix Release Date:
                    1/Jul/11