Ad
  • Custom User Avatar

    You say you're passing in 0.1, but nobody can observe that. All our programs can see is you're passing in 0.100000000000000006. You might even have passed in 0.999999999999999999 or 1.00000000000000009, but we won't be able to tell.

    So you need to tell us what is your target precision.

  • Custom User Avatar

    You say you're passing in 0.1, but nobody can observe that. All our programs can see is you're passing in 0.100000000000000006. You might even have passed in 0.999999999999999999 or 1.00000000000000009, but we won't be able to tell.

  • Custom User Avatar

    You say you're passing in 0.1, but nobody can observe that. All our programs can see is you're passing in 0.100000000000000006. You might even have passed in 0.999999999999999999 or 1.00000000000000009, but we won't be able to tell.

  • Default User Avatar

    multiply(3, 0.1) = 0.3 (result has the precision driven by the inputs)
    multiply(3, 0.100000000000000006) = 0.300000000000000018

    This is impossible since 0.1 == 0.100000000000000006 for doubles.

  • Custom User Avatar

    The precesion of result will be driven by the precision of input numbers on which operation is performed.

    In number system 0.1 === 0.1000000000000000....... not(0.100000000000000006).

    0.1 is handled as 0.100000000000000006 in javascript computer world and the objective is to perform operations without getting in details about how your numbers are being handled in javascript. The result should be based on actual number system of mathematics.

  • Custom User Avatar

    @JohanWiltink, @Unnamed: I understand your point, but keep you technical expertise of how numbers are handled in computers aside for a while and read out the following:

    The precision of the result of arithmetic operation on any two given numbers will depend on the precision of the inputs available.
    So, if we say
    0.1 it would equal to 0.100000000000000000... In other words, $0.1 billion will be equal to $0.10000000000000..billion not $0.100000000000000006 billion or something.

    Now, the objective is this kata is to handle the number system for arithmetic operations in such a way that, 0.1 which has precision of a single decimal digit should be used as it is for operations rather than how our computers manipulate it to behave it as 0.100000000000000006.

    The precision should be decided by the user input on which he wants to perform the operation rather than how any machine or any language treats that.

    Hence,
    multiply(3, 0.1) = 0.3 (result has the precision driven by the inputs)
    multiply(3, 0.100000000000000006) = 0.300000000000000018

    I hope it helps!

  • Custom User Avatar

    Mishraas, if you want to multiply with precision, you'll need to specify the precision of the inputs. This cannot be done with floats.

    Unnamed is right and you're wrong. Sorry.

  • Default User Avatar

    First of all, 0.1 != 0.100000000000000006.

    Truncated to the size of double precision mantissa, it is.

    But in javascript while playing around with floating/decimal numbers we often come across results which are slighlty deviated from the actual result.

    It depends on a definition of actual result.

    For e.g.: 3 * 0.1 should be equal to 0.3 as per traditional mathematics with a precision to single decimal number, but javascript gives the result as 0.30000000000000004.

    True. But the difference is not because of something about multiplication but because of the representation of 0.1.

    The objective is to calculate the result without introducing a factor like 0.00000000000000004 in above example.

    So how should I know that 3 * 0.100000000000000006 should be 0.3 instead of whatever it is in mathematics?

    This kata is specific for javascript only.

    Actually, more than js. It's the same in most other languages.

  • Custom User Avatar

    First of all, 0.1 != 0.100000000000000006. But in javascript while playing around with floating/decimal numbers we often come across results which are slighlty deviated from the actual result. For e.g.: 3 * 0.1 should be equal to 0.3 as per traditional mathematics with a precision to single decimal number, but javascript gives the result as 0.30000000000000004.

    The objective is to calculate the result without introducing a factor like 0.00000000000000004 in above example.

    This kata is specific for javascript only.

  • Default User Avatar

    You can't multiply two given numbers more precisely than a * b. The numbers aren't multiplied imprecisely, just not all of them can be represented precisely. Why is 3 * 0.1 expected to equal 0.3? 0.1 == 0.100000000000000006, so if for some reason 3 * 0.1 == 0.3 then 3 * 0.100000000000000006 == 0.3. The description says nothing about what the result should be, so for me it sounds like it's about adding a magically inferred error to the product.

  • Custom User Avatar

    I'm pretty sure the point of it is its complete vagueness.

  • Custom User Avatar

    I have added more test cases to cover multiple possible scenarios as well. Thanks!

  • Default User Avatar

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

  • Default User Avatar

    Very good first kata! Please give us more!

  • Custom User Avatar

    Sounds not simple, was simple;-)... good one:-)!

  • Loading more items...