Skip to content

feat: add comprehensive F32 math library - #929

Open
victormeloasm wants to merge 1 commit into
bendlang:mainfrom
victormeloasm:feat/math-library
Open

victormeloasm wants to merge 1 commit into
bendlang:mainfrom
victormeloasm:feat/math-library

Conversation

@victormeloasm

Copy link
Copy Markdown
Contributor

Adds a comprehensive F32 math library to Bend, modeled after the C math.h API and adapted to Bend's current numeric type system.

The new library includes trigonometric, hyperbolic, exponential, logarithmic, power, rounding, remainder, gamma, error-function, IEEE-754 classification and helper operations, along with common mathematical constants such as PI, E and sqrt(2).

This PR also adds the backend support required for operations that cannot be implemented accurately using only existing F32 primitives, with consistent behavior across the C and JavaScript backends.

Highlights include:

  • new bend2/math.bend module
  • C99/C11-style math functions applicable to F32
  • additional C23-style functions such as sinpi, cospi, tanpi, pown, powr, rootn, rsqrt, exp2m1 and log2p1
  • explicit handling for signed zero, subnormals, NaN and infinities
  • fused F32 FMA support
  • numerically stable implementations for sensitive operations such as expm1, log1p, erf, erfc, scaling and integer powers
  • new regression, edge-case and backend consistency tests

Local validation:

  • bun gates/repo.ts: PASS 48/48
  • randomized C/JS differential testing and IEEE-754 edge-case testing passed
  • UBSan, float-cast-overflow, ASan and LeakSanitizer testing passed
  • gates/test.ts could not be executed locally because it requires access to the project's private mini-cluster SSH host

@victormeloasm

Copy link
Copy Markdown
Contributor Author

Bump

@pjcavalcanti pjcavalcanti self-assigned this Sep 22, 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