Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling square roots #2

Open
1011X opened this issue Feb 9, 2019 · 0 comments
Open

Handling square roots #2

1011X opened this issue Feb 9, 2019 · 0 comments

Comments

@1011X
Copy link
Owner

1011X commented Feb 9, 2019

A design decision must be made for how to calculate and handle square root values.

There's two ways to handle square roots:

  • Return Some value only when it's an exact result (i.e. the numerator and denominator are perfect squares), or None otherwise.
  • Calculate a value close to its floating-point equivalent using continued fractions, and document the issues with saving or reusing such a value. This could be difficult to calculate dynamically, so maybe it's better to do some statistical analysis and pick a fixed number of iterations to do for all numbers.

There's also the option of providing both through different method names. The first method can be called checked_sqrt and the second one sqrt, where checked_sqrt can be mentioned in the documentation for sqrt in case that behavior is preferable to the user.

Update: sqrt() has been implemented by converting to float, using {f32,f64}::sqrt(), and then converting back to the corresponding rational value. The float conversion is derived from this post. Some tests should be written to ensure that it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant