Skip to content

F32.from_nat wraps values at 2^32 #1609

Open

Description

@oxura

F32.from_nat narrows through U32.from_nat, so it silently wraps at 2^32 even though these values fit the supported Nat range.

import Base

def main() -> IO(Unit):
  IO.print(F32.show(F32.from_nat(Nat.double(2147483648n))))

On 7e120d5 this prints 0. The input is 4294967296, an exactly representable F32; it should not become zero. The literal is built with Nat.double because Nat literals themselves stop at U32_MAX. Current main has the same definition.

The fix removes the narrowing conversion, with a direct Nat-to-F32 intrinsic on compiled lanes. I checked the 2^32 boundary, rounding just above half an ulp, a tie to even, and the maximum supported Nat on Bun and native C; the existing number kit still passes. AI-assisted investigation and fix.

Activity

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