Currently, both Float
and Double
individually declares the property bitPattern
and the initializer init(bitPattern: UInt32/UInt64)
.
How come BinaryFloatingPoint
doesn't have an associated type BitPattern
, and the above property and initializer as requirements, ie something like this:
public protocol BinaryFloatingPoint : ExpressibleByFloatLiteral, FloatingPoint {
/.../
associatedtype BitPattern: FixedWidthInteger, UnsignedInteger
public var bitPattern: Self.BitPattern { get }
public init(bitPattern: Self.BitPattern)
/.../
}
?
Note that BinaryFloatingPoint
already has eg:
public init(sign: FloatingPointSign, exponentBitPattern: Self.RawExponent, significandBitPattern: Self.RawSignificand)
Edit:
Ah, of course, Float80
doesn't have the bitPattern
property and the init(bitPattern:)
initializer ... sigh:
// Workaround for Float80-inflicted limitations of BinaryFloatingPoint:
protocol UsableBinaryFloatingPoint : BinaryFloatingPoint {
associatedtype BitPattern: FixedWidthInteger, UnsignedInteger
var bitPattern: BitPattern { get }
init(bitPattern: BitPattern)
}
extension Float: UsableBinaryFloatingPoint { }
extension Double: UsableBinaryFloatingPoint { }