https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124391

            Bug ID: 124391
           Summary: Surprising rounding of std::float16_t literals
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janschultke at googlemail dot com
  Target Milestone: ---

https://godbolt.org/z/rMK5sqdr7

auto f16 = 512.749999999f16;
auto f32 = 4194304.749999999f32;

This generates the following:

"f16":
        .value  24578
"f32":
        .long   1249902593

Evidently, 512.749999999f16 is being rounded UP to 513/0x6002, despite
512.5/0x6001 being the mathematically closer nearest representable value.

This behavior is inconsistent with the rounding of std::float32_t.
4194304.749999999f32 is mathematically closer to 4194304.5/0x4a800001 than to
4194305/0x4a800002, so it gets rounded DOWN.

This behavior is also inconsistent with Clang, which rounds 512.749999999f16
DOWN to 512.5/0x6001.

Reply via email to