# Extend Square Root to Work With Floating Points?

The exercise currently works with integer input and output. Perhaps it should be extended to work with floating points?

Interesting. What do you see as the learning benefit? Any specific tracks youâ€™re thinking of this for?

My main motivation was to make sure whatever someone implements works correctly, i.e. it also works with real numbers and not only with square integers. Another advantage is that we can require the solution to be within certain precision away from the exact square root. This might help people understand topics like numerical errors, rate of convergence, etc.

Ok, thanks. Iâ€™d welcome otherâ€™s thoughts on this. It has the downside that it would break all the existing solutions but the upside of potentially teaching more

1 Like

Assuming all the existing solutions only support perfect squares, I would suggest that changing this to support other values might make more sense as a second/additional exercise.

I do not see that currently extending this from the studentâ€™s standpoint breaks any tests.

So does the current specification get in the way of extending this if you want to explore?

The statement:

The exercise currently works with integer input and output. Perhaps it should be extended to work with floating points?

does not say that it currently only works with integer input and output.

Iâ€™d welcome otherâ€™s thoughts on this.

Yes, same, I am curious to see what the others think.

Iâ€™ve found Methods of computing square roots - Wikipedia is a nice tidy algorithm for integer square roots

Counter-argument then, if we presume that currently all studentâ€™s code would work with any new tests, what is the advantage to adding more tests?

Counter-argument then, if we presume that currently all studentâ€™s code would work with any new tests, what is the advantage to adding more tests?

To verify that the solution really works. There is no guarantee that an algorithm for computing the square root of a number (e.g. Newtonâ€™s method) is implemented correctly just because it works on square integers.

Another advantage is to require certain precision (e.g. 1.0e-6) and force students to tune the algorithm (e.g. add more iterations).

None, which is my point. They are not, from what I can see, restricted from exploring this already.

The current description explicitly mentions the exercise being about â€śnatural radicansâ€ť, so working with natural numbers (integers): problem-specifications/exercises/square-root/description.md at main Â· exercism/problem-specifications Â· GitHub If we were to change the exercise, we should also update the text. Thatâ€™s not to say we canâ€™t, but itâ€™s relatively invasive.

This might help people understand topics like numerical errors, rate of convergence, etc.

I think these are nice things to help students work with, Iâ€™m only wondering whether extending the existing exercise is the best way to do this.

1 Like