Ad
  • 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

    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.

  • Custom User Avatar

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

  • Custom User Avatar

    Please add further details in description section of this kata.