Skip to content

Fix -0.0 serialization for implicit-presence float and double fields#1443

Open
timostamm wants to merge 1 commit into
mainfrom
tstamm/Fix--0.0-serialization-for-implicit-presence-float-and-double-fields
Open

Fix -0.0 serialization for implicit-presence float and double fields#1443
timostamm wants to merge 1 commit into
mainfrom
tstamm/Fix--0.0-serialization-for-implicit-presence-float-and-double-fields

Conversation

@timostamm

Copy link
Copy Markdown
Member

With implicit presence (the proto3 default for singular scalar fields), the value decides whether a field is serialized:
false, "", and 0 are considered not set, and are omitted from the wire.

But there is a special case for float and double fields. The proto3 spec on Default Field Values:

If a float or double value is set to +0 it will not be serialized, but -0 is considered distinct and will be serialized.

We missed this detail. isScalarZeroValue from @bufbuild/protobuf/reflect treats -0.0 as a zero value, so a singular float or double field set to -0.0 is omitted during serialization, losing its sign in a round-trip.

This fixes the behavior to align with the spec. Note that this is a behavior change: -0.0 in a singular implicit-presence field is now written to the wire instead of omitted. The function equals inherits the fixed behavior for field presence, but float and double values are still compared with IEEE semantics: NaN does not equal NaN, and -0 equals 0.

@timostamm timostamm requested a review from ajeetdsouza June 19, 2026 15:33
@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
protobuf-es Ignored Ignored Jun 19, 2026 3:33pm

Request Review

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