Skip to content

fix(ffi): GF16 round-to-nearest + overflow→Inf + full GF4-24 encode/decode#553

Merged
gHashTag merged 2 commits intomasterfrom
fix/ffi-gf16-encode-bugs
Apr 29, 2026
Merged

fix(ffi): GF16 round-to-nearest + overflow→Inf + full GF4-24 encode/decode#553
gHashTag merged 2 commits intomasterfrom
fix/ffi-gf16-encode-bugs

Conversation

@gHashTag
Copy link
Copy Markdown
Owner

Summary

Fixes 4 bugs and adds missing encode/decode for 5 formats.

Bug Fixes

BUG-001 (#546): encode_gf16 mantissa truncation → round-to-nearest-even

  • Detects half-ULP boundary (lower_14 > 0x2000)
  • Tie-breaks to even mantissa bit
  • Carries overflow into exponent

BUG-002 (#547): encode_gf16 overflow saturates to max-finite → canonical ±Inf

  • exp >= max_exp now returns exp=63, mant=0 (IEEE 754 Inf)
  • gf16_is_inf() correctly returns true

BUG-003 (#548): gf32_from_f64 paperware fix

  • Clarified GF32 uses IEEE fp32 layout for FPGA drop-in compatibility

A1 (#545): Duplicate of BUG-001 — fixed by same mantissa rounding change

API Completeness (#549)

Added from_f32/to_f32 for GF4, GF8, GF12, GF20, GF24:

Format Layout Bias Round-to-nearest
GF4 [s:1][e:1][m:2] 1 Yes
GF8 [s:1][e:3][m:4] 3 Yes
GF12 [s:1][e:4][m:7] 7 Yes
GF20 [s:1][e:7][m:12] 63 Yes
GF24 [s:1][e:9][m:14] 255 Yes

All 7 GoldenFloat formats now have full encode/decode/arithmetic.

Tests (16 passing)

  • GF16: roundtrip (near-one, half, basic), overflow→Inf, f32::MAX→Inf, -overflow→-Inf, zero, Inf, NaN
  • GF4/8/12/20/24: roundtrip with accuracy bounds
  • GF8: overflow→Inf

Closes #546, Closes #547, Closes #548, Closes #549, Closes #545

…/decode

BUG-001 (#546): encode_gf16 mantissa truncation → round-to-nearest-even
  - Add half-ULP detection + tie-break to even
  - Carry into exponent on mantissa overflow

BUG-002 (#547): encode_gf16 overflow saturates to max-finite → +Inf
  - exp >= max_exp now returns canonical ±Inf (exp=max, mant=0)

BUG-003 (#548): gf32_from_f64 — fix comment (GF32 = IEEE fp32 for FPGA)

API-COMPLETENESS (#549): add from_f32/to_f32 for GF4/8/12/20/24
  - All 7 GoldenFloat formats now have full encode/decode
  - Round-to-nearest-even on all formats
  - Proper overflow→Inf and underflow→zero handling

build.rs: tolerate CC_FORCE_DISABLE for testing without C deps

16 tests passing

Closes #546, Closes #547, Closes #548, Closes #549
@github-actions
Copy link
Copy Markdown

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions
Copy link
Copy Markdown

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

gHashTag added a commit that referenced this pull request Apr 29, 2026
Closes #546, Closes #547, Closes #548, Closes #549, Closes #545
@gHashTag gHashTag force-pushed the fix/ffi-gf16-encode-bugs branch from 6e28a8d to 0e88fb6 Compare April 29, 2026 19:27
@github-actions
Copy link
Copy Markdown

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

Closes #546, Closes #547, Closes #548, Closes #549, Closes #545
@gHashTag gHashTag force-pushed the fix/ffi-gf16-encode-bugs branch from 0e88fb6 to 7b4476c Compare April 29, 2026 19:29
@github-actions
Copy link
Copy Markdown

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@gHashTag gHashTag merged commit f6e64ad into master Apr 29, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment