[swift-evolution] Proposal: A standard library Fraction type
harlan at harlanhaskins.com
Mon Dec 7 02:01:45 CST 2015
If Swift 3 is going to focus on re-thinking the Numerics in the system, it might be worth considering adding a Fraction (or Rational) type to the standard library. This, coupled with an arbitrary-precision integer type, would be a great way to handle arbitrary-precision decimal arithmetic, and can alleviate almost all the pain points of floating-point math.
There exist now some really nice implementations of Fractions, but the ones I’ve seen haven’t been implemented fully generically.
My favorite is this one: https://gist.github.com/JadenGeller/5e80ebf32442acc62e8e <https://gist.github.com/JadenGeller/5e80ebf32442acc62e8e>
I’d love to see some standard library support with rock-solid, fast implementations of all the common algorithms (GCD, LCD, LCM, reduction, etc) and good conformance to the builtin integer protocols. Maybe even FloatLiteralConvertible, too, with some logic for converting rational floats.
- Harlan Haskins
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution