Skip to content

F32.round loses the sign of negative zero #1611

Closed

Description

@oxura

F32.round turns negative zero into positive zero. It does the same when a negative fraction rounds to zero, including the negative half under the existing ties-toward-positive-infinity rule.

import Base

def main() -> IO(Unit):
  do IO<Unit>:
    IO.print(U32.show(F32.bits(F32.round(F32.neg(0.0)))))
    IO.print(F32.show(F32.div(1.0, F32.round(F32.neg(0.1)))))

On 7e120d5, this prints 0 and inf; preserving the sign would give 2147483648 and -inf. Current main has the same definition. The sign is observable through both the public bit conversion and ordinary arithmetic.

I kept the existing tie rule and restored the input sign only when the rounded result is zero. Negative zero, negative fractions, the half boundary and the number kit now pass on Bun and native C. AI-assisted investigation and fix.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions