Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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 as0.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.@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 to0.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 as0.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!
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 to0.3
as per traditional mathematics with a precision to single decimal number, but javascript gives the result as0.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.
I have added more test cases to cover multiple possible scenarios as well. Thanks!
Please add further details in description section of this kata.