Skip to content

Conversation

jasonbobier
Copy link
Owner

This PR adds two least common multiple functions:

  • lcm(T, T) -> T
    A simple version that will trap if T is not capable of representing the result.

  • leastCommonMultiple(T, T) throws -> T
    A throwing version that instead of trapping, throws and error that contains the full width result if it cannot be represented in T.

Unlike other functions, such as gcd(), it is not uncommon for least common multiples to be unrepresentable in its fixed width integer. The lcm() function is offered in cases where this doesn't matter or where it is extremely unlikely to happen, such as BigNums. In other cases, the leastCommonMultiple() function is available. This will throw instead of trapping and the thrown error will contain the high and low words of the result saving the user from having to call leastCommonMultiple() again (and thus incurring the internal gcd() costs).

Renamed lcm<FixedWidthInteger> to leastCommonMultiple.
Updated gcd call to use magnitude instead.
Renamed tests.
@jasonbobier
Copy link
Owner Author

This PR requires that apple#320 be resolved and merged and should not be merged until that is done.

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