You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
A design decision must be made for how to calculate and handle square root values.
There's two ways to handle square roots:
Some
value only when it's an exact result (i.e. the numerator and denominator are perfect squares), orNone
otherwise.There's also the option of providing both through different method names. The first method can be called
checked_sqrt
and the second onesqrt
, wherechecked_sqrt
can be mentioned in the documentation forsqrt
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.The text was updated successfully, but these errors were encountered: