[swift-evolution] f suffix for float32 literals, h suffix for float16 literals

Steve Canon scanon at apple.com
Fri Nov 3 14:05:31 CDT 2017


If/when 16b floats were added to the standard lib, you would just write:

    let vertexData: [Float16] = [ 1, 0, 0.5, 1 ]

I should note that something like vertex coordinates is usually better modeled with a more specific type than [Float], like SCNVector4 or simd.float4 or your own type, which also solves this problem:

    import SceneKit
    let vertexData = SCNVector4(1, 0, 0.5, 1)

    import simd
    let vertexData = float4(1, 0, 0.5, 1)

(NB both of these frameworks are Apple-specific).

- Steve

Sent from my iPhone

> On Nov 3, 2017, at 14:58, Tony Allevato via swift-evolution <swift-evolution at swift.org> wrote:
> 
> You can write this for the first thing that you want:
> 
>     let vertexData: [Float] = [1.0, 0.0, 0.5, 1.0]
> 
> I don't know enough about 16-bit floats to comment on those.
> 
> 
>> On Fri, Nov 3, 2017 at 11:26 AM nick ralabate via swift-evolution <swift-evolution at swift.org> wrote:
>> I think it would be helpful for graphics programmers to specify vertex data inline without surrounding every value with Float(4.0).
>> 
>> Something like this:
>> 
>> let vertexData = [ 1.0f, 0.0f, 0.5f, 1.0f ]
>> 
>> Also, it would be great if Swift had a type for half-floats to match the iPhone GPU:
>> 
>> let vertexData = [ 1.0h, 0.0h, 0.5h, 1.0h]
>> 
>> 
>> Thanks!
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171103/cf75f658/attachment.html>


More information about the swift-evolution mailing list