#38450·openvino

BF16 round-to-nearest-even does not round values just above the halfway point

Author: YugShah1510Created Sep 28, 2026Updated Sep 28, 2026

Description

The current implementation of ov::bfloat16::round_to_nearest_even(float) appears to produce an incorrect result for FP32 values whose discarded lower 16 bits are just above the halfway point.

The current implementation is:

cpp
static uint16_t round_to_nearest_even(float x) {
    return static_cast<uint16_t>((cu32(x) + ((cu32(x) & 0x00010000) >> 1)) >> 16);
}

Reproduction

For these FP32 bit patterns, the current implementation produces:

0x3f807fff -> 0x3f80
0x3f808000 -> 0x3f80
0x3f808001 -> 0x3f80

For round-to-nearest-even, the expected results are:

0x3f807fff -> 0x3f80
0x3f808000 -> 0x3f80
0x3f808001 -> 0x3f81

The last case is the discrepancy: the discarded 16 bits are 0x8001, which is greater than the halfway value 0x8000, so the BF16 result should round upward.

Additional observation

The Intel CPU scaled-attention SIMD implementation uses a rounding bias of 0x7fff + LSB, which explicitly accounts for the discarded bits and the retained BF16 LSB.

The existing BF16 unit tests cover several rounding cases, but do not appear to cover the boundary immediately above halfway (0x8001).

Question

Is the current scalar round_to_nearest_even implementation intentional, or should it be updated to correctly implement round-to-nearest-even for values above the halfway point?

If this behavior is considered a bug, I would be happy to contribute a focused regression test and fix.

Source: openvinotoolkit/openvino