[swift-evolution] Proposal: A standard library Fraction type
scanon at apple.com
Mon Dec 7 08:45:03 CST 2015
Musical time signatures is an odd case, because you really have pairs of integers (i.e. if they were rational numbers, then 6/8 would be the same as 3/4. They are not the same).
> On Dec 7, 2015, at 9:36 AM, T.J. Usiyan <griotspeak at gmail.com> wrote:
> Musical time signatures and note duration. Visual code with proportional relationships.
> On Mon, Dec 7, 2015 at 7:41 PM, Stephen Canon via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Can you guys specify some of the use cases that you have in mind for a Rational type? You mention "alleviating the pain points of floating-point math,” but rationals tend to be used *very* differently from floating-point types in computation.
> – Steve
>> On Dec 7, 2015, at 5:44 AM, Davide De Franceschi via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> While I agree that a Rational type, one that would preserve quotient and denominator info, would be very nice, I think that it's more fit for a Math framework.
>> If we're just talking about a type that holds precise decimal info, I think making NSDecimal (planned to be renamed as Decimal in the future) usable is what we should do.
>>> On 7 Dec 2015, at 10:28, T.J. Usiyan via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> I'm all for a stdlib Rational Type. I've written one as well and would be glad not to have to include it as a dependency everywhere.
>>> On Mon, Dec 7, 2015 at 1:31 PM, Harlan Haskins via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 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
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution