Skip to content

Cleaned up GCD,updated GCD tests to Swift Testing, and added LCM. #310

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

Closed
wants to merge 9 commits into from

Conversation

jasonbobier
Copy link

By returning T.Magnitude instead of T, gcd(a, b) no longer will produce fatal errors and removes a few special case lines of code. This allows the end user of the api to decide how to handle Signed Fixed Width Integer overflows.

Moved the tests to Swift Testing and updated for new code.

Also renamed the files for clarity and to match the other naming in the IntegerUtilties.

Renamed the source files.
Updated gcd to remove fatalError.
Updated gcd tests to use Swift Testing and removed fatalError tests.
Renamed the source files.
Updated gcd to remove fatalError.
Updated gcd tests to use Swift Testing and removed fatalError tests.
Added lcm for both BinaryInteger and FixedWidthInteger.
Added tests for both.
@jasonbobier
Copy link
Author

Note that this is also prep for an lcm implementation which will be in a separate PR.

@jasonbobier
Copy link
Author

Ended up adding the lcm to here as well. With fixed width integers, lcm can overflow fairly often. In that case, this code will throw an error that contains the overflow value so that the caller has a chance to use the lcm result in a larger type.

@jasonbobier jasonbobier changed the title Cleaned up GCD and updated GCD tests to Swift Testing Cleaned up GCD and updated GCD tests to Swift Testing and added LCM. Jun 10, 2025
@jasonbobier jasonbobier changed the title Cleaned up GCD and updated GCD tests to Swift Testing and added LCM. Cleaned up GCD,updated GCD tests to Swift Testing, and added LCM. Jun 11, 2025
@jasonbobier jasonbobier closed this Aug 7, 2025
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

Successfully merging this pull request may close these issues.

1 participant