[swift-evolution] FloatingPoint does not conform to ExpressibleByFloatLiteral
Xiaodi Wu
xiaodi.wu at gmail.com
Mon Jan 15 22:27:49 CST 2018
On Mon, Jan 15, 2018 at 20:37 Nevin Brackett-Rozinsky <
nevin.brackettrozinsky at gmail.com> wrote:
> On Mon, Jan 15, 2018 at 8:51 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
>> On Mon, Jan 15, 2018 at 19:20 Nevin Brackett-Rozinsky <
>> nevin.brackettrozinsky at gmail.com> wrote:
>>
>>> All I’m saying is the current situation seems semantically wrong. As in,
>>> how can a type claim to be a floating point number, if it *literally*
>>> cannot be represented by a floating point number?
>>>
>>
>> Again, you can think of it that way, but what I’m saying is that
>> “FloatLiteral” is a misnomer: semantically, a conforming type is
>> specifically claiming that it is expressible by a _binary_ floating point
>> number.
>>
>
> I strongly disagree. To say that it is a “misnomer” implies that the
> semantics are correct and the problem is with the name.
>
> However, in Swift a floating point literal consists of certain patterns of
> characters in source code, as specified by the language grammar. Thus it is
> meaningful and correct to say that certain types can be expressed as
> floating point literals. We have a protocol for exactly that purpose: to
> indicate that conforming types can be written as floating point literals.
>
I understand that you disagree with the current semantics, but they aren't
arbitrary. You know, I’m sure, that we can write integer literals in any of
several bases. For example, `0xffff` is an integer literal which represents
the same value as `65535`:
0xffff == 65535 // true
It doesn’t matter in which base you write the literal, it represents some
particular _binary integer_ up to a maximum of 2048 (binary) digits.
Likewise, we can write floating-point literals in any of several bases. For
example:
0x1.5bf0a8b145769p1 == 2.7182818284590451 // true
It doesn't matter in which base you write the literal, it represents some
particular _binary floating-point value_ up to a maximum of 63 or 52
fractional bits, depending on the platform.
That protocol is spelled ExpressibleByFloatLiteral, which reflects the
> meaning that we want and should have. The name is correct, the problem is
> with the implementation.
>
I get that you want float literals to have semantics other than what they
have. Again, that's a different conversation. I'm simply explaining that
the current semantics are not by accident, and that the implementation
isn't a buggy execution of the semantics you think they should have, but an
exact execution of semantics you may not agree with but nonetheless
deliberately chosen.
If you want to argue that, after we fix the buggy implementation of
> ExpressibleByFloatLiteral, then we should introduce a new protocol named
> ExpressibleByBinaryFloatLiteral, that might be a discussion worth having.
> But for the existing protocol, renaming it would not solve the underlying
> issue.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180115/5a9ab6ee/attachment.html>
More information about the swift-evolution
mailing list