init(bigEndian/littleEndian:) for floating-point types?

FixedWidthInteger has neat initializers:

init(bigEndian value: Self)
init(littleEndian value: Self)

Shouldn't there be corresponding initializers for Float and Double? There’s

init(bitPattern: UInt64)

But it would be nice if there was

init(bigEndianBitPattern: UInt64)
init(littelEndianBitPattern: UInt64)

I suppose I could do

let d = Double(bitPattern: UInt64(bigEndian: bytes))

Is that the best approach? Thing is, I'm not sure how to make the BinaryFloatingPoint equivalent of this:

    -> T where T : FixedWidthInteger
    let size = MemoryLayout<T>.stride
    let v: T = self.idx..<self.idx + size).withUnsafeBytes { $0.load(as: T.self) }
    self.idx += size
    if self.bigEndian
        return T(bigEndian: v)
        return T(littleEndian: v)
Terms of Service

Privacy Policy

Cookie Policy