Skip to content

fix(base): retain representable F32.hypot lengths - #1515

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
sebastian-griego:fix/f32-hypot-range
Oct 12, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
sebastian-griego:fix/f32-hypot-range

Conversation

@sebastian-griego

Copy link
Copy Markdown
Contributor

F32.hypot squares both components before it takes a square root. Those squares can become infinity or zero even when the vector length is representable. For example, hypot(1e30, 0) returns infinity and hypot(1e-30, 0) returns zero.

Take the absolute values, order them as hi and lo, and compute hi * sqrt(1 + (lo / hi)^2). Handle zero and infinity before division. The existing NaN result policy stays the same. The examples above return 1e30 and 1e-30 with this change.

This change uses existing Base operations. It adds no compiler primitive, dependency, or effect. The parser and compiler token caps stay unchanged.

Add two regressions. The first checks axis lengths across the F32 exponent range, scaled 3-4-5 triangles, argument order, negative components, the largest finite value, subnormal values, signed zero, infinity, and NaN. The second checks parallel vector lengths with the GPU entry point.

Validation:

  • Rebased onto current main. The repository gate passes 54/54. git diff --check passes.
  • All 22 selected math regression programs pass in source, native C, Bun, and Node. The local plan records 121 checks, including controls that reproduce the failure on unchanged upstream code.
  • The parallel regression and full exponent-range axis checks pass on Metal. The parallel regression also passes with GPU execution disabled.
  • 10,640 reference vectors pass in C, Bun, and Node. Linux C and Bun checks also pass. The largest observed difference from the host hypotf or F32-rounded Math.hypot reference is two units in the last place. The checks reject an output infinity for a finite reference and an output zero for a positive reference. This sample does not establish a universal error bound or correct rounding.
  • The complete generated exponent-regression program passes AddressSanitizer and UndefinedBehaviorSanitizer at -O0 on macOS and Linux. Linux leak detection is enabled.

CUDA and the repository cluster were not tested. The performance, proof, and release gates were not run. This patch makes no performance claim.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 12, 2026
@Lorenzobattistela
Lorenzobattistela merged commit c25ee78 into bendlang:main Oct 12, 2026
1 check passed
@Lorenzobattistela Lorenzobattistela mentioned this pull request Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants