4 ms·
I'd consider that new code a step backwards since it removes the vital words "Newton-Raphson". If I didn't recognize the algorithm I might have a very hard tim
by dagw 16y ago
I'd consider that new code a step backwards since it removes the vital words "Newton-Raphson". If I didn't recognize the algorithm I might have a very hard time working out exactly how and why that lump of code approximates a square root. With the words Newton-Raphson included somewhere I could easily look it up and find out everything I need to know about not only how and why it works but also its strength and weaknesses. Personally whenever I use some non-trivial algorithm I haven't made up I tend to include a comment pointing to the book or paper I got it from so that others can get the canonical description of what the algorithm does.
Ideally I'd even like to see a brief comment on why Newton-Raphson was chosen as well. Is there a good reason why I shouldn't replace that code with some other square root approximation technique or was it chosen because it was the only algorithm the author knew?
- edanm 16y agoI agree that the algorithm name should appear somewhere. I would probably refactor the code as Jeff says, but add a comment that describes the function, probably with details about why it's implemented the way it is.