[swift-evolution] Implicit truncation

Greg Parker gparker at apple.com
Tue May 30 17:52:33 CDT 2017


> On May 26, 2017, at 12:04 AM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I've often wondered if even just "bitPattern" might suffice, as the truncating or extending of it should not be particularly surprising.

Being explicit about bit pattern truncation or extension is valuable. It helps catch bugs where the bit count is not what the author expected. In Swift it is especially important for types like Int and CGFloat which have platform-dependent sizes.

    let x: Int64 = …
    let y = Int(bitPattern: x)  // if truncation is implicit then this may be surprising on 32-bit platforms

    let a: UInt32 = …
    let b = Int(bitPattern: a) // if zero- or sign-extension is implicit then this may be surprising on 64-bit platforms


-- 
Greg Parker     gparker at apple.com <mailto:gparker at apple.com>     Runtime Wrangler


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170530/1049a9d6/attachment.html>


More information about the swift-evolution mailing list