[swift-evolution] [Discussion] Arbitrary precision integer and float literal protocols
brent at architechies.com
Mon Apr 3 02:51:49 CDT 2017
> On Mar 31, 2017, at 10:08 AM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> (This would leave non-binary floats in the lurch, but we're pretty much doing that already—try initializing `Decimal` through its `ExpressibleByFloatLiteral` conformance sometime and you'll see what I mean. I would support changing its name to `ExpressibleByBinaryFloatLiteral`.)
> This is actually one of the greatest deficiencies I see in `ExpressibleByFloatLiteral`. Here, I would disagree with you and say that I'd like to see `ExpressibleByFloatLiteral` improved precisely because of its very poor functionality for `Decimal`. IMO, while saying that floating point literals are only meant to work in binary would mean that the current design is "correct," it's unfortunate and unjustifiable that `0.1` doesn't mean 0.1.
> Honestly, I'd even prefer to allow `String` as a floating point literal type (because after all that's what Decimal is really doing under the hood) than to just give up on this aspect of float literals altogether. I don't have a good answer here but I would hate to see this opportunity lost to fix the deficiency for real.
I don't suggest giving up on base-ten floating-point literals, but I think that what we have is ideal (or nearly so) for binary types and we should invent a different mechanism for decimal types. The first step in doing that is to rename the binary protocol so its function is clear.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution