Skip to content

Feature request: Floating point parsing #25

@lorrden

Description

@lorrden

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions