Skip to content

Decode integers into floats - #58

Merged
lalinsky merged 1 commit into
mainfrom
int-to-float
Nov 29, 2026
Merged

lalinsky merged 1 commit into
mainfrom
int-to-float

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Encoders without a separate float type, such as JavaScript's, write 5.0 as the integer 5, so a client sending {price: 5} to an f64 field got error.UnexpectedToken.

Decoding into f16, f32 or f64, optional or not, now accepts every MessagePack integer form: positive and negative fixints, uint8 to uint64 and int8 to int64. Large integers round to the nearest float, and one too large for the type decodes to infinity, the same as a float64 that does not fit. Other kinds of value are still error.UnexpectedToken.

The integer handling is in a separate out-of-line function, so the float32/float64 path is the same as before.

Encoders without a separate float type, such as JavaScript's, write 5.0 as
the integer 5, so a float field received `UnexpectedToken`. Every integer
form now decodes into f16, f32 and f64, rounding where needed and giving
infinity when the value is too large for the type.

The integer path is out of line so the float path stays as small as before.
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The float decoder now converts integer-encoded MessagePack values to floats, including values that overflow to infinity. Tests cover integer widths, optional f32 decoding, and unsupported tokens. The changelog documents the behavior.

Changes: Integer-to-float decoding

Layer / File(s) Summary
Decode integer tokens
src/float.zig, CHANGELOG.md
unpackFloat converts fixints and signed and unsigned integer widths to floats. Tests cover f64, optional f32, overflow to f16 infinity, and error.UnexpectedToken. The changelog records integer-to-float decoding.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Merge Risk: Minimal · up to 5bcd6

This change lets float fields accept integer-encoded MessagePack values, such as those from JavaScript encoders. Other value kinds still return the same errors. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Decode integers into floats" matches the main change: unpackFloat now decodes MessagePack integer forms (fixints, uint8-64, int8-64) into f16/f32/f64, as the changelog, file summary, and PR…
Description check Passed The description explains the motivation (encoders such as JavaScript's write 5.0 as integer 5, which caused error.UnexpectedToken), lists the integer forms now accepted, covers rounding and overflow t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Decode integers into floats" matches the main change: unpackFloat now decodes MessagePack integer forms (fixints, uint8-64, int8-64) into f16/f32/f64, as the changelog, file summary, and PR objectives describe. It is concise and specific, and a teammate scanning history would understand the primary change.

Full details: Description check

Explanation

The description explains the motivation (encoders such as JavaScript's write 5.0 as integer 5, which caused error.UnexpectedToken), lists the integer forms now accepted, covers rounding and overflow to infinity, notes that other value kinds still error, and mentions the separate out-of-line function. This matches the src/float.zig and CHANGELOG.md changes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0666e97d-ef4e-436b-beb4-7c1bf9064120
Commits

Reviewing files that changed from the base of the PR and between 5cfffa9 and 5bcd6a0.

Files selected for processing: 2

  • CHANGELOG.md
  • src/float.zig

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@lalinsky
lalinsky merged commit 5c105e7 into main Nov 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant