JetForMe
(Rick M)
1
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:
func
get<T>()
-> T where T : FixedWidthInteger
{
let size = MemoryLayout<T>.stride
let v: T = self.data.subdata(in: self.idx..<self.idx + size).withUnsafeBytes { $0.load(as: T.self) }
self.idx += size
if self.bigEndian
{
return T(bigEndian: v)
}
else
{
return T(littleEndian: v)
}
}