Skip to content

Fix directed rounding for negative subnormals - #171

Open
chiliec wants to merge 1 commit into
cockroachdb:masterfrom
chiliec:fix-subnormal-directed-rounding
Open

chiliec wants to merge 1 commit into
cockroachdb:masterfrom
chiliec:fix-subnormal-directed-rounding

Conversation

@chiliec

@chiliec chiliec commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

RoundCeiling and RoundFloor came out swapped for a negative subnormal: the ceiling moved the value away from zero and the floor towards it.

In the subnormal path of setExponent the rounding sign was read from the truncated integer part, which is zero (and therefore non-negative) for a value between -1 and 0, so a negative subnormal was rounded as if it were positive. The fix uses the sign of the value itself.

Fixes #170.

Added a test covering ceiling/floor on a negative and a positive subnormal; it fails before the change and passes after, and the full suite stays green.

In the subnormal path of setExponent the rounding sign was taken from
the truncated integer part, which is zero (and so non-negative) for a
value between -1 and 0. RoundCeiling and RoundFloor therefore came out
swapped for a negative subnormal. Use the sign of the value itself.

Fixes cockroachdb#170.
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.

RoundCeiling and RoundFloor come out swapped for a negative subnormal

1 participant