Skip to content

fix(ron): round-trip non-finite floats (inf/-inf/NaN) - #170

Merged
knickish merged 1 commit into
not-fl3:masterfrom
jaideeppyne:fix/ron-nonfinite-float-roundtrip
Aug 26, 2026
Merged

fix(ron): round-trip non-finite floats (inf/-inf/NaN)#170
knickish merged 1 commit into
not-fl3:masterfrom
jaideeppyne:fix/ron-nonfinite-float-roundtrip

Conversation

@jaideeppyne

Copy link
Copy Markdown
Contributor

SerRon serializes non-finite floats as inf, -inf and NaN (matching the RON specification and the reference ron crate), but the RON deserializer rejected all of these tokens. As a result deserialize_ron(serialize_ron(x)) returned an error for any f32/f64 that was infinite or NaN, including values nested inside a struct/Vec/Option.

Before:

f64  inf: ron="inf"  -> RON DE ERR: Unexpected token Ident expected floating point
f64 -inf: ron="-inf" -> RON DE ERR: Cannot parse number
f64  NaN: ron="NaN"  -> RON DE ERR: Unexpected token Ident expected floating point

Bare inf/NaN are scanned as identifiers, so they're now accepted in as_f64 when a float is expected; -inf/+inf reach the number branch after the sign, so the inf literal is parsed there. Serialization is unchanged. Adds a regression test covering scalars, the literal forms (inf/+inf/-inf/NaN), and non-finite floats nested in a struct. (The sibling TOML module already handles these tokens; RON was simply missed.)

SerRon serializes non-finite floats as `inf`, `-inf` and `NaN` (matching
the RON specification and the reference `ron` crate via `{:?}` formatting),
but the RON deserializer rejected all of these tokens. As a result
`deserialize_ron(serialize_ron(x))` returned an error for any float that was
infinite or NaN, breaking the round-trip contract for both `f32` and `f64`.

Bare `inf`/`NaN` are scanned as identifiers, so accept them in `as_f64` when
a float is expected; `-inf`/`+inf` reach the number branch after the sign, so
parse the `inf` literal there. Adds a regression test covering scalars, the
literal forms, and non-finite floats nested inside a struct/Vec/Option.
@knickish
knickish merged commit 3f89a70 into not-fl3:master Aug 26, 2026
16 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.

3 participants