Skip to content

Keep floating-point round from changing already integral values #554

Closed

Description

@LunaStev

round_f32 and round_f64 implement rounding by adding/subtracting 0.5 before floor/ceil. That intermediate itself rounds in floating point. For example, f32 value 8388609 and f64 value 4503599627370497 are already exact integers, but adding 0.5 lands on a halfway value that rounds to the next even integer. A round-to-integer operation should leave those inputs unchanged. Values immediately below 0.5 can similarly cross the threshold during addition; the positive branch also loses negative zero.

Code evidence:

Acceptance:

  • Implement the intended nearest-integer/ties-away behavior without an intermediate addition that changes the rounding decision.
  • Cover odd integral values near 2^23 for f32 and 2^52 for f64, their negatives, and values on both sides of half-integer boundaries.
  • Preserve signed zero and define NaN/infinity handling consistently with the existing float helpers.
  • Use exact bit-pattern or exact-integer checks for these cases, not only approximate comparisons.

Audit status: static source inspection against canonical master ea74c2dafc31da876e5561f2d176ba719f5a0458 on 2026-09-10. No compiler build, test execution, implementation change or local reproduction was performed for this report. The examples describe the source-derived behavior to verify when implementing the fix.

Activity

  1. added
    bug
    help wanted
    on Sep 10, 2026
  2. added a commit that references this issue on Sep 16, 2026
    451cc7a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions