Skip to content

bitstring: Fix f16 rounding to nearest even - #2457

Open
petermm wants to merge 1 commit into
atomvm:release-0.7from
petermm:fix/f16-rounding-2447
Open

petermm wants to merge 1 commit into
atomvm:release-0.7from
petermm:fix/f16-rounding-2447

Conversation

@petermm

@petermm petermm commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Constructing a :16/float segment rounded halfway values away from zero and truncated subnormals. A tie such as 6546.0 was stored as 6548.0 instead of 6544.0, and 1.0e-6 was truncated instead of rounded, so the bytes differed from BEAM's.

Round the discarded bits to nearest, ties to even, in both the normal and subnormal paths. Rounding may now carry from the largest subnormal into the smallest normal number, or round a tie at the bottom of the subnormal range to zero.

Fixes: #2447

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

Constructing a `:16/float` segment rounded halfway values away from
zero and truncated subnormals. A tie such as 6546.0 was stored as
6548.0 instead of 6544.0, and 1.0e-6 was truncated instead of
rounded, so the bytes differed from BEAM's.

Round the discarded bits to nearest, ties to even, in both the
normal and subnormal paths. Rounding may now carry from the largest
subnormal into the smallest normal number, or round a tie at the
bottom of the subnormal range to zero.

Fixes: atomvm#2447
Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
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