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

Xiaodi Wu xiaodi.wu at gmail.com
Fri Nov 3 16:12:12 CDT 2017


On Fri, Nov 3, 2017 at 1:26 PM, 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).
>

Two pointers:

a. You never actually want to write `Float(4.0)`, which casts a
`FloatLiteralType aka Double` with value `4.0` to `Float`. You want `4 as
Float`.  This is an issue which has come up several times before on this
list.

b. You don't need to do this for every value in an array. You only need to
annotate one; probably the first one for your readers' sanity:

```
let vertexData = [1 as Float, 0, 0.5, 1]
```

Alternatively, you can use explicit type annotations as shown by others.


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171103/85ca5a62/attachment.html>


More information about the swift-evolution mailing list