apple / apple/swift-binary-parsing

Feature request: Floating point parsing

Open
#25 3 comments 0 reactions 1 assignee Claimed by @natecook1000 View on GitHub
Dominant language
Swift
Stars
387
Forks
24
Avg merge
1h 3m
Merged PRs (30d)
2

Description

I could not find a way to read floating point numbers in the package out of the box, sure we can do something like this:

```swift
extension Double {
init(parsingLittleEndian input: inout ParserSpan) throws {
let tmp = try UInt64(parsingLittleEndian: &input)
self = withUnsafePointer(to: tmp) { ptr in
let rawPtr = UnsafeRawPointer(ptr)
return rawPtr.load(as: Double.self)
}
}
}
```

The above is obviously limited to IEEE types, but as other formats like MIL-STD-1750A exist, some kind of extensible floating point encoding mechanism would be useful.

I could think of these formats being somewhat useful / common where obviously, at least IEEE float32 and float64 are very prevalent:

- IEEE float16
- IEEE float32
- IEEE float64
- IEEE float128
- IEEE float256
- Extended x86 format (80 bits)
- bfloat16
- Nvidia tensor float
- AMD fp24
- PXR24
- MIL-STD-1750 formats

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.