Ad
  • Custom User Avatar

    Fixed

  • Custom User Avatar

    You are right, Expected: 1.98, Result: 1.98 is a terrible error message.
    Also, round(X * 100) * 0.01 is indeed a trap I did not think about.

    I have changed the test output from

    Expected: equal to 9.45
    Actual: 9.45
    

    to

    Expected: equal to 9.45 (precisely: 9.44999999999999929e+00)
    Actual: 9.45 (precisely: 9.45000009999999868e+00)
    

    Better?

  • Custom User Avatar

    Fixed

  • Default User Avatar

    I can confirm I had the same issue in my solution, thanks for the tip!

  • Custom User Avatar

    If you think the tests are wrong, please post your solution (surrounded by a line with just three backticks (```) and marked as "having spoiler content") and the failed tests.

  • Custom User Avatar

    There are many values that cannot be represented exactly in IEEE-754 floating point numbers.
    Instead the nearest representable value will be used. E.g. 9.45 is stored as 9.44999999999999929 and 9.46 is stored as 9.46000000000000085.
    The task asks for some value v, rounded to two decimal places (let's call it r).
    The rounding makes the result unambiguous. You should return the nearest representable value to r.
    That's what is tested in JavaScript (Test.assertEquals(actual, expected);), C++ (Assert::That(actual, Equals(expected));), Python (Test.assert_equals(actual, expected)), etc.
    All that sound complicated but it's not. Compute v as exact as possible and then use the rounding functions of the programming language to obtain r from v.

  • Custom User Avatar

    Yep. It's easy to code once you know the answer, but you have to figure out the answer...

  • Default User Avatar

    Thanks for your feedback. I wrote this originally in JavaScript and then trusted the translations after checking them to the best of my ability. Can someone fluent in C++ help with this? That seems to be the language that has had the most trouble with this kata.