Skip to content

fix(math): fix factorial signature and add missing constants/functions#251

Merged
dbrattli merged 2 commits intomainfrom
repo-assist/fix-math-factorial-and-add-constants-758322e10a61d336
Apr 16, 2026
Merged

fix(math): fix factorial signature and add missing constants/functions#251
dbrattli merged 2 commits intomainfrom
repo-assist/fix-math-factorial-and-add-constants-758322e10a61d336

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Problem

Two issues with Fable.Python.Math bindings:

  1. Bug: math.factorial has wrong signature for Python 3.12+
    The binding declared abstract factorial: x: float -> float, but Python 3.12 removed float support — math.factorial(5.0) now raises TypeError: 'float' object cannot be interpreted as an integer. Since pyproject.toml requires python >= 3.12, this binding (and its test) was broken.

  2. Missing constants and functions
    The math module was missing many commonly-used members: the five constants (pi, e, tau, inf, nan), and over a dozen functions (sqrt, degrees, radians, trunc, hypot, fsum, isqrt, prod, perm, hyperbolic functions, and special functions).

Fix

  • Changed factorial signature to int -> int and updated the test to pass integer literals.
  • Added all five math constants (pi, e, tau, inf, nan).
  • Added missing functions: sqrt, degrees, radians, trunc, hypot, fsum, isqrt, prod, perm, acosh, asinh, atanh, cosh, sinh, tanh, erf, erfc, gamma, lgamma.
  • Fixed math.dist to accept float[] arrays (the Python function takes two point sequences, not two scalars).
  • Reorganised the IExports interface with section comments matching the Python docs structure.
  • Added tests for all new members.

Trade-offs

  • This is additive (no existing signatures removed). The only breaking change is factorial: float -> floatfactorial: int -> int, which aligns with the Python 3.12 API. Any F# code passing floats to factorial was already broken at runtime.
  • math.dist signature changed from float -> float -> float to float[] -> float[] -> float. The old curried scalar version was incorrect (Python's dist takes two sequences of coordinates, not two scalars).

Checklist

  • Fixed math.factorial signature (float -> floatint -> int)
  • Added constants: pi, e, tau, inf, nan
  • Added functions: sqrt, degrees, radians, trunc, hypot, fsum, isqrt, prod, perm, all hyperbolic and special functions
  • Fixed math.dist signature
  • Updated and extended TestMath.fs
  • Updated CHANGELOG.md

Note

🔒 Integrity filter blocked 10 items

The following items were blocked because they don't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Repo Assist · ● 2M ·

- Fix math.factorial: float -> float changed to int -> int for Python 3.12+
  compatibility (float args raise TypeError since Python 3.12)
- Add missing constants: pi, e, tau, inf, nan
- Add missing functions: sqrt, degrees, radians, trunc, hypot, fsum,
  isqrt, prod, perm, acosh, asinh, atanh, cosh, sinh, tanh, erf, erfc,
  gamma, lgamma
- Fix math.dist signature to accept float arrays (multi-dimensional)
- Add tests for all new additions
- Update tests to use integer literals for factorial

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dbrattli dbrattli marked this pull request as ready for review April 16, 2026 06:03
Replace IEnumerable<T> with seq<T> in fsum/prod to fix build (missing
import). Add tests for nan, prod, perm, dist, hyperbolic functions,
and special functions. Move Unreleased section above rc.3 in CHANGELOG.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dbrattli dbrattli changed the title [Repo Assist] fix(math): fix factorial signature and add missing constants/functions fix(math): [Repo Assist] fix factorial signature and add missing constants/functions Apr 16, 2026
@dbrattli dbrattli changed the title fix(math): [Repo Assist] fix factorial signature and add missing constants/functions fix(math): fix factorial signature and add missing constants/functions Apr 16, 2026
@dbrattli dbrattli merged commit 7b32de0 into main Apr 16, 2026
17 of 18 checks passed
@dbrattli dbrattli deleted the repo-assist/fix-math-factorial-and-add-constants-758322e10a61d336 branch April 16, 2026 06:20
dbrattli added a commit that referenced this pull request Apr 16, 2026
Update tests for comb, copysign, fmod, pow, atan2, dist to use tupled
calling convention matching the corrected type signatures. Restore
PR #251 entries that were dropped from the Unreleased CHANGELOG section.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dbrattli added a commit that referenced this pull request Apr 16, 2026
…dings (#253)

* fix(math): correct type signatures for copysign, fmod and curried bindings

- math.copysign: fix y parameter type from int to float (Python always
  takes two floats)
- math.fmod: fix parameter and return types from int to float (computes
  floating-point remainder, not integer modulo)
- math.comb, math.pow, math.atan2, math.dist: convert curried parameter
  syntax to tupled for consistency with all other multi-parameter
  bindings in the codebase

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: update tests for tupled params, restore CHANGELOG entries

Update tests for comb, copysign, fmod, pow, atan2, dist to use tupled
calling convention matching the corrected type signatures. Restore
PR #251 entries that were dropped from the Unreleased CHANGELOG section.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Dag Brattli <dag@brattli.net>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant