6 kyu

Floating-point Approximation (II)

32 of 1,113g964
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • janAkali Avatar

    Nim: same issue as in half of other Nim katas - tests are green even if you fail (doesn't count as completion, but very confusing).

    I've hit the same bug in my own Nim translations, it can be solved by having only one check per test.

  • B1ts Avatar

    Groovy: initial solution is missing import: import java.util.function.DoubleUnaryOperator;

  • vall-ball Avatar

    PowerShell. What is a mistake: Expected: {0 0.99 0.14 -0.98 -0.28 0.93 0.41 -0.88 -0.54 0.8 0.65 -0.72} But was: {0 0.99 0.14 -0.98 -0.28 0.93 0.41 -0.88 -0.54 0.8 0.65 -0.72} ?

  • DeNöff Avatar

    I dont understand, what am I approximating? I just use f and push the values until it fits.

  • hobovsky Avatar

    Update to Nim 1.6.

    If after merging it turns out that 1.6 did not get active, or that 1.0 did not get inactive, let me know. It's a known bug, and there's a known fix for this.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • B1ts Avatar

    Is this even solvable in Perl? Whatever precision I'm trying to use, I cannot get the exact results as expected. -0.98999 expects -0.99 and similar. Am I missing something obvious?

  • src201261730 Avatar

    This comment has been hidden.

  • ejini战神 Avatar
    • Node 14 should be enabled (Refer this and this for more info)

    • Python new test framework should be used (Refer this & this for more detail)

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

  • ejini战神 Avatar

    Missing sample and fixed tests whereby l is not zero and f is a log function across most languages

  • FArekkusu Avatar

    Have you fixed the C version here?

  • imjasonmiller Avatar

    I've forked the Rust translation in order to update it to Rust 1.49 and updated rand::Rng::gen_range to its new signature that takes a std::ops::Range.

  • Murmority Avatar

    Hi, buddy! I hope, I haven't miss something in my solution. I use JS in my way, and catch the next problem: from the first to the third test my way works pretty clear, without any errors, but in random test every second "out" is wrong, and have such type
    Expected: '[0.69, 1.18, 1.51, 1.76, 1.96, 2.13, 2.27, 2.39, 2.5, 2.6, 2.69, 2.78, 2.85, 2.92]',
    instead got: '[0.69, 1.18, 0.94, 1.34, 1.63, 1.86, 2.04, 2.19, 2.33, 2.44, 2.55, 2.64, 2.73, 2.92]'.
    What can I do with it? Thanks a lot in advance!

  • user7820265 Avatar

    The author almost has written out the answer.

  • dundro Avatar

    Language: Scala

    Random test result:

    l: 7.5 u: 18.0 n: 15 Actual: 2.01, 2.1, 2.18, 2.26, 2.33, 2.39, 2.45, 2.51, 2.57, 2.62, 2.67, 2.72, 2.76, 2.8, 2.85 Expect: 2.01, 2.1, 2.18, 2.26, 2.33, 2.39, 2.45, 2.51, 2.57, 2.62, 2.67, 2.72, 2.76, 2.8, 2.85 -

    What that "-" means?

  • Warrior101 Avatar

    Language: Scala

    I forgot to add the lower bound to the argument of f and still passed the tests. Looking at the test cases the lower bound is always fixed to 0.

  • monadius Avatar

    This comment has been hidden.

  • mmalkavian Avatar

    @g964: while we are on topic, can you tell me how to round d here? I've tried your suggested rounding method:

    d = ((((u - l) / n) * 100.0) / 100.0)
    d = math.floor((((u - l) / n) * 100.0) / 100.0)
    

    and I pass all the tests but not the random tests with the first version.

  • dulot Avatar

    Quite good!

  • geoffp Avatar

    The instructions start out calling the lower limit m, then switch to calling it l.

  • geoffp Avatar

    For functions returning doubles, I think the best practice is to test approximate correctness (with code like "abs(expected - actual) < epsilon") rather than relying on rounding or truncation, which can cause problems unless you specify exactly how the rounding is to be done (and the function code follows your instructions to the letter). Note, for example, that "floor(x * 100.0) * 0.01" and "floor(x * 100.0) / 100.0" give different results for some values of x.

  • JohanWiltink Avatar

    JS random tests: you're starting the interval at l+l instead of l.

  • Unnamed Avatar

    In both Ruby and Python my solution doesn't pass every second random test. I'm not sure if I missed something but it passed all the basic tests and half of the random tests...

  • Unnamed Avatar

    Should the numbers be floored or truncated? For negative numbers the results are different.

  • Unnamed Avatar

    In Python: NameError: name 'sin' is not defined