Ad
  • Custom User Avatar

    Are you sure about this statement?

    I was going off real world, where whether we do * or / first does not matter,

  • Custom User Avatar

    Do not use WolframAlpha to verify floating-point arithmetic results. Use Dart itself or any other programming language (Python, JavaScript, etc.). For example, your solution (where I replaced Frac with double everywhere) fails the following test:

    Expected: <64.69433890577507>
      Actual: <64.69433890577508>
    expression = -95+9/-7--25+45/48/-47+96+40
    

    Let's verify the expected result with Dart itself:

    void main() {
      double expr = -95+9/-7- -25+45/48/-47+96+40;
      print("expr = $expr");
    }
    

    The result is expr = 64.69433890577507.

    Here is a small example for which your solution returns a wrong result:

    Expected: <0.7714285714285716>
      Actual: <0.7714285714285715>
    expression = 9/7*3/5
    

    It seems like you compute it as (9/7) * (3/5) which is not correct since * and / have the same precedence. So it should be computed as ((9/7) * 3) / 5.

    I admit that the kata description is not precise. I plan to update it at some point to make it clear how all expressions should be evaluated. It is also important to specify that all intermediate results should be computed with double precision.

  • Custom User Avatar

    There are no issues with Dart tests. Use double everywhere and make sure that you evaluate all operations from left to right if they have the same precedence. Floating-point arithmetic is not random. You always get the same result if you perform all operations in the correct order.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Thanks a lot, this issue was not only in dart but in all languages :)