Releases: swift-standards/swift-ieee-754
Releases · swift-standards/swift-ieee-754
0.2.0 - Array Extensions
New Features
Array Serialization/Deserialization
Added support for deserializing multiple Float and Double values from byte arrays:
API Additions
[Double] Extensions
extension [Double] {
public init?<C: Collection>(bytes: C, endianness: [UInt8].Endianness = .little)
where C.Element == UInt8
}[Float] Extensions
extension [Float] {
public init?<C: Collection>(bytes: C, endianness: [UInt8].Endianness = .little)
where C.Element == UInt8
}Usage Examples
Deserialize multiple Doubles:
let bytes: [UInt8] = [
0x6E, 0x86, 0x1B, 0xF0, 0xF9, 0x21, 0x09, 0x40, // 3.14159
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, // 1.0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 // 2.0
]
let doubles = [Double](bytes: bytes)
// Optional([3.14159, 1.0, 2.0])Deserialize multiple Floats:
let bytes: [UInt8] = [
0xD0, 0x0F, 0x49, 0x40, // 3.14159
0x00, 0x00, 0x80, 0x3F, // 1.0
0x00, 0x00, 0x00, 0x40 // 2.0
]
let floats = [Float](bytes: bytes)
// Optional([3.14159, 1.0, 2.0])Big-endian support:
let doubles = [Double](bytes: bytes, endianness: .big)Features
- Works with any
CollectionofUInt8 - Returns
nilif byte count is not a multiple of element size (4 for Float, 8 for Double) - Preserves all special values (NaN, infinity, signed zero, subnormals)
- Supports both little-endian (default) and big-endian byte order
- Efficient implementation with capacity pre-reservation
Testing
Comprehensive test coverage added:
- 224 tests in 60 suites (increased from 174 in 55)
- Parameterized tests for invalid byte counts
- Subnormal and extreme value preservation tests
- Mixed endianness validation tests
- Collection types compatibility tests
- 12 new performance benchmarks for array operations
Performance benchmarks demonstrate excellent efficiency:
- Deserialize 1000 elements: ~700µs
- Round-trip 10,000 random values: ~10ms
Documentation
- Updated README with array extension examples
- Enhanced API documentation
- Added usage examples for common patterns
Full Changelog: 0.1.0...0.2.0
0.1.0
IEEE 754 v0.1.0
Swift implementation of IEEE 754-2019 binary floating-point standard for canonical serialization.
Features
- Binary32 and Binary64 formats: Full support for Float and Double serialization
- Endianness control: Little-endian and big-endian byte order support
- Zero-copy deserialization: High-performance unsafe memory operations
- Cross-module inlining: Optimized with
@inlinableand@_transparent - Special values: Comprehensive handling of NaN, infinity, subnormals, and signed zero
- Pure Swift: No Foundation dependencies, suitable for Swift Embedded
Installation
dependencies: [
.package(url: "https://github.com/swift-standards/swift-ieee-754.git", from: "0.1.0")
]Quick Start
import IEEE_754
// Double to bytes
let bytes = (3.14159).bytes()
// Bytes to Double
let value = Double(bytes: bytes)Testing
181 tests across 11 suites covering:
- Round-trip conversions
- Special values and edge cases
- Performance benchmarks
- Concurrent access safety
Performance
Benchmarked on Apple Silicon:
- Serialization: 0.5 microseconds per Double
- Deserialization: 0.5 microseconds per Double
- Round-trip 10,000 conversions: 5ms
Requirements
- Swift 6.0+
- macOS 15.0+ / iOS 18.0+ / tvOS 18.0+ / watchOS 11.0+