A few weeks ago, Joe Groff challenged users on Twitter to create a
Rational<T> type making use of the new integer protocols implemented for
Swift 4. As it happens, I'd already started a project to try out these new
number protocols. Now that I think the most embarrassing bugs have been
squashed in that project, I thought I'd share it here in case anyone else
might find it useful.
NumericAnnex <https://github.com/xwu/NumericAnnex> is meant to supplement
the standard library's numerics facilities in Swift 4. At the moment, it
* Extensions to BinaryInteger for GCD, LCM, and exponentiation
* Protocols Math (refines SignedNumeric), Real (refines Math and
FloatingPoint), and PRNG (refines Sequence and IteratorProtocol)
* Types Complex<T>, Rational<T>, and Random
Documentation is available at <https://xwu.github.io/NumericAnnex/>.
I'd love to hear feedback. I'll follow up shortly on Swift Evolution with
some thoughts on future improvements to integer protocols based on this