zerodds-float128 1.0.0-rc.7

IEEE 754 binary128 in software: the sixteen bytes CDR gives `long double`, as a value type with exact conversions, IEEE comparison, and round-tripping decimal.
Documentation
  • Coverage
  • 100%
    32 out of 32 items documented0 out of 8 items with examples
  • Size
  • Source code size: 212.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 626.5 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • zero-objects/zero-dds
    18 5 2
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SandraK82

zerodds-float128

IEEE 754 binary128, in software, for the sixteen bytes CDR gives long double.

use zerodds_float128::Float128;

// Sixteen bytes off the wire and sixteen back, unchanged.
let value = Float128::from_be_bytes(bytes);
assert_eq!(value.to_be_bytes(), bytes);

// A value a double can hold converts; one it cannot is refused by name.
let narrow: f64 = value.to_f64()?;

Why it exists

CORBA 3.3 part 2 §9.3.1.3 gives long double one sign bit, a fifteen-bit exponent and a 112-bit fraction, and DDS-XTypes 1.3 Table 31 names the result: quadruple precision, sixteen bytes, aligned to eight. Rust has no stable f128, so this project used to write a double and eight zero bytes for it — the right length, the wrong value, and no error. Carrying the value needs no arithmetic, only bit manipulation and long division, so the gap was a gap by choice.

What it does

  • Lossless sixteen-byte round trip in both byte orders. CORBA Figure 9.2 reverses the whole sixteen bytes between orders, not two halves, and that is what RTI Connext was measured doing.
  • Exact conversion from f32, f64 and the integers, and back with the inexact cases returned as an Inexact carrying the rounded value — never rounded in silence.
  • IEEE comparison, plus total_cmp for a @key member and a sorted expectation, where a None for NaN is not an answer.
  • Decimal in and out, correctly rounded against the exact value, so a JSON value file can carry one. to_shortest_decimal writes the fewest digits that read back; to_exact_decimal writes all of them.
  • The x87 80-bit extended format, in both directions, because Fast DDS and OpenDDS put that on the wire on x86-64 and a reader that only knows the conformant form cannot read the field.

What it does not do

Arithmetic. No Add, no Mul, no sqrt. Nothing on the wire path needs them and a half-correct one is worse than none; docs/float128-column.md §6 says what adding them would take and how it would be checked.

The oracle

tests/oracle/ holds 518 values run through GCC's __float128 on the Linux test host, compared in both directions: their printer against our parser, and their parser against our printer. A crate that implements a format cannot be its own second opinion.

See docs/float128-column.md for the vendor measurements this crate is answering.