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

Added tests for gcd and lcm for other integer data types. #35451

Merged
merged 1 commit into from
Apr 19, 2020

Conversation

ravibitsgoa
Copy link
Contributor

Added tests for all signed and unsigned integer data types.
Improved the doctests of gcd and lcm.

Currently gcd(-5) = -5. Should we keep it that way or make it abs(-5) = 5?

@dkarrasch dkarrasch added the test This change adds or pertains to unit tests label Apr 14, 2020
@ravibitsgoa
Copy link
Contributor Author

Can anyone review this PR which adds tests for previously untested integer data types for gcd and lcm?
Previous code tested gcd and lcm methods for only Int32 and Int64.

@StefanKarpinski StefanKarpinski merged commit dd738f9 into JuliaLang:master Apr 19, 2020
@ravibitsgoa ravibitsgoa deleted the ravibitsgoa/intgcd branch April 19, 2020 17:33
@KristofferC
Copy link
Sponsor Member

KristofferC commented Jun 1, 2020

@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Jun 1, 2020

This puts us between a rock and a hard place: on is it better to break compatibility or give the wrong answer sometimes if there's overflow? One solution would be to add a checked_abs(x::Number) = abs(x) fallback, but I think that's too dangerous. Another would be to used

checked_abs_if_available(x::Number) = applicable(checked_abs, x) ? checked_abs(x) : abs(x)

for this code in gcd an lcm. That would allow it to keep working for types that haven't defined checked_abs but not foist that unsafeness on anyone who explicitly calls checked_abs. It might be even better to put an off-by-default deprecation warning in the definition saying "please define checked_abs(::T)."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants