Skip to content

Commit 55be653

Browse files
committed
Remove unusable init overloads taking [UInt8].IEEE754
[UInt8].IEEE754 has internal init, so users cannot construct it directly. Providing init overloads that accept it as parameter is pointless since the only way to get [UInt8].IEEE754 is via bytes.ieee754 property. Changes: - Remove Double.init?(_ ieee754: [UInt8].IEEE754, endianness:) - Remove Float.init?(_ ieee754: [UInt8].IEEE754, endianness:) - Update tests to use Direct(bytes:) instead of Type(bytes.ieee754) Available APIs remain: - Double(bytes: data) - canonical init - [UInt8](3.14159) - canonical serialization - Double.ieee754(bytes) - type method - value.ieee754.bytes() - instance method Tests: All 12 tests passing
1 parent ce9e30a commit 55be653

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

Sources/IEEE_754/Float+IEEE_754.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,6 @@ extension Float {
5252
}
5353
self = value
5454
}
55-
56-
/// Creates Float from namespace-wrapped IEEE 754 binary32 bytes
57-
///
58-
/// Convenience init for transforming namespace-wrapped bytes to Float.
59-
/// Delegates to `IEEE_754.Binary32.value(from:endianness:)`.
60-
///
61-
/// - Parameters:
62-
/// - ieee754: Namespace-wrapped byte array
63-
/// - endianness: Byte order of input bytes
64-
/// - Returns: nil if bytes.count ≠ 4
65-
///
66-
/// Example:
67-
/// ```swift
68-
/// let value = Float(bytes.ieee754)
69-
/// let value = Float(bytes.ieee754, endianness: .big)
70-
/// ```
71-
public init?(_ ieee754: [UInt8].IEEE754, endianness: [UInt8].Endianness = .little) {
72-
guard let value = IEEE_754.Binary32.value(from: ieee754.bytes, endianness: endianness) else {
73-
return nil
74-
}
75-
self = value
76-
}
7755
}
7856

7957
// MARK: - Type-level Methods

Tests/IEEE_754_Tests/IEEE_754_Tests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct Binary64Tests {
1212
func doubleRoundTrip() {
1313
let original: Double = 3.14159265358979323846
1414
let bytes = original.ieee754.bytes()
15-
let restored = Double(bytes.ieee754)
15+
let restored = Double(bytes: bytes)
1616

1717
#expect(restored == original)
1818
}
@@ -30,7 +30,7 @@ struct Binary64Tests {
3030
func doubleBigEndian() {
3131
let value: Double = 3.14159
3232
let bytes = value.ieee754.bytes(endianness: .big)
33-
let restored = Double(bytes.ieee754, endianness: .big)
33+
let restored = Double(bytes: bytes, endianness: .big)
3434

3535
#expect(restored == value)
3636
}
@@ -66,7 +66,7 @@ struct Binary32Tests {
6666
func floatRoundTrip() {
6767
let original: Float = 3.14159
6868
let bytes = original.ieee754.bytes()
69-
let restored = Float(bytes.ieee754)
69+
let restored = Float(bytes: bytes)
7070

7171
#expect(restored == original)
7272
}
@@ -84,7 +84,7 @@ struct Binary32Tests {
8484
func floatBigEndian() {
8585
let value: Float = 3.14
8686
let bytes = value.ieee754.bytes(endianness: .big)
87-
let restored = Float(bytes.ieee754, endianness: .big)
87+
let restored = Float(bytes: bytes, endianness: .big)
8888

8989
#expect(restored == value)
9090
}

0 commit comments

Comments
 (0)