Beta
Long Division
12xyfonix
Loading description...
Mathematics
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Testing expects numerical
NaN
s andInfinity
s, but does not check if normal digits areString
s orNumber
s. It's not specified either.It should be specified ( preferably as
Number
s, though theString
s'-'
and'.'
grate ), and it should be tested.I took out the floating point numbers ( and I fixed the typo in the random test headers ). I did not take out the negative zeroes; you can reverse engineer what is expected from testing.
This still does not make it a well-written or well-designed kata ( which is a shame really ), but at least it's solvable now.
Because the reference solution isn't even arbitrary precision real arithmetic, the answer derived by the reference solution is simply wrong. e.g:
The correct result is
0.25663885990172302292589578160906176584827770888387331907749834099698695209475275668754975679175249426790238934990...
as shown by Wolfram Alpha:http://www.wolframalpha.com/input/?i=1000000000000000+%2F+3896526038118073
Edit: as another demonstration of the incorrect behaviour, I tested some inputs where
a === b
, and the reference solution aren't even giving1.0000...
:Needs tests with large initial dividend and a small divisor. Very large (or small) quotients aren't tested at all.
Since this is a kata about big decimal, the typical stuff should be banned, aka all the ways that can cause
require('bignumber.js')
to work.Also there is no point in identifying
-0
. It's considered practically the same to everything except toObject.is
, and even(-0).toString()
gives0
. It's analogous to saying that allNaN
s are equal, which is absurd, an artifact of IEEE floats standard and not a good practice in any means.There is no point in getting digits below precision of a double, because they aren't even resolvable. Even a change in the tiniest significant bit in the divisor will cause the result to change significantly after the 16th digit (aka
1/Number.MAX_SAFE_INTEGER
).I don't think you really understand the intracacies of arbitrary precision real arithmetic. They simply aren't done this way. To begin with, passing numbers in as floating point values is already a grave mistake. They should be passed in as strings (but then this kata would be a duplicate to https://www.codewars.com/kata/divide-numbers-as-strings).
Random tests section titles has a typo: Things like
-2345658712136251.5 = 7811398559714191 =
should be-2345658712136251.5 / 7811398559714191 =
.Nice kata! Looks like it covers every possible edge case. Got me thinking quite a bit. And more over - this could be a useful function in many other applications! Thanks