Skip to content

Commit 8f33975

Browse files
github-actions[bot]Copilotdbrattliclaude
authored
fix(math): correct type signatures for copysign, fmod and curried bindings (#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>
1 parent 7b32de0 commit 8f33975

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ All notable changes to this project will be documented in this file.
1212
### 🐞 Bug Fixes
1313

1414
* Fix `math.factorial` binding: changed signature from `float -> float` to `int -> int` to match Python 3.12+ where float arguments raise `TypeError`. Fixes test to use integer literals.
15+
* Fix `math.copysign` binding: `y` parameter was incorrectly typed as `int`, now correctly `float`
16+
* Fix `math.fmod` binding: parameters were incorrectly typed as `int -> int -> int`, now correctly `float * float -> float`
17+
* Fix `math.comb`, `math.pow`, `math.atan2`, `math.dist` bindings: converted curried parameter syntax to tupled for consistency
1518

1619
### ✨ Enhancements
1720

src/stdlib/Math.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ type IExports =
4040
abstract ceil: x: float -> int
4141
/// Return the number of ways to choose k items from n items (n choose k)
4242
/// See https://docs.python.org/3/library/math.html#math.comb
43-
abstract comb: n: int -> k: int -> int
43+
abstract comb: n: int * k: int -> int
4444
/// Return a float with the magnitude of x and the sign of y
4545
/// See https://docs.python.org/3/library/math.html#math.copysign
46-
abstract copysign: x: float -> y: int -> float
46+
abstract copysign: x: float * y: float -> float
4747
/// Return the absolute value of x
4848
/// See https://docs.python.org/3/library/math.html#math.fabs
4949
abstract fabs: x: float -> float
@@ -59,7 +59,7 @@ type IExports =
5959
abstract floor: x: float -> int
6060
/// Return the floating-point remainder of x / y
6161
/// See https://docs.python.org/3/library/math.html#math.fmod
62-
abstract fmod: x: int -> y: int -> int
62+
abstract fmod: x: float * y: float -> float
6363
/// Return an accurate floating-point sum of values in the iterable
6464
/// See https://docs.python.org/3/library/math.html#math.fsum
6565
abstract fsum: iterable: float seq -> float
@@ -132,7 +132,7 @@ type IExports =
132132
abstract log10: x: float -> float
133133
/// Return x raised to the power y
134134
/// See https://docs.python.org/3/library/math.html#math.pow
135-
abstract pow: x: float -> y: float -> float
135+
abstract pow: x: float * y: float -> float
136136
/// Return the square root of x
137137
/// See https://docs.python.org/3/library/math.html#math.sqrt
138138
abstract sqrt: x: float -> float
@@ -152,7 +152,7 @@ type IExports =
152152
abstract atan: x: float -> float
153153
/// Return the arc tangent of y/x in radians
154154
/// See https://docs.python.org/3/library/math.html#math.atan2
155-
abstract atan2: y: float -> x: float -> float
155+
abstract atan2: y: float * x: float -> float
156156
/// Return the cosine of x radians
157157
/// See https://docs.python.org/3/library/math.html#math.cos
158158
abstract cos: x: float -> float
@@ -218,7 +218,7 @@ type IExports =
218218

219219
/// Return the Euclidean distance between two points p and q
220220
/// See https://docs.python.org/3/library/math.html#math.dist
221-
abstract dist: p: float[] -> q: float[] -> float
221+
abstract dist: p: float[] * q: float[] -> float
222222

223223
/// Mathematical functions
224224
[<ImportAll("math")>]

test/TestMath.fs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ let ``test floor works`` () =
1717

1818
[<Fact>]
1919
let ``test comb works`` () =
20-
math.comb 5 2 |> equal 10
21-
math.comb 10 3 |> equal 120
20+
math.comb (5, 2) |> equal 10
21+
math.comb (10, 3) |> equal 120
2222

2323
[<Fact>]
2424
let ``test copysign works`` () =
25-
math.copysign 1.0 -1 |> equal -1.0
26-
math.copysign -1.0 1 |> equal 1.0
25+
math.copysign (1.0, -1.0) |> equal -1.0
26+
math.copysign (-1.0, 1.0) |> equal 1.0
2727

2828
[<Fact>]
2929
let ``test fabs works`` () =
@@ -37,8 +37,8 @@ let ``test factorial works`` () =
3737

3838
[<Fact>]
3939
let ``test fmod works`` () =
40-
math.fmod 10 3 |> equal 1
41-
math.fmod 7 2 |> equal 1
40+
math.fmod (10.0, 3.0) |> equal 1.0
41+
math.fmod (7.0, 2.0) |> equal 1.0
4242

4343
[<Fact>]
4444
let ``test gcd works`` () =
@@ -89,8 +89,8 @@ let ``test log10 works`` () =
8989

9090
[<Fact>]
9191
let ``test pow works`` () =
92-
math.pow 2.0 3.0 |> equal 8.0
93-
math.pow 10.0 2.0 |> equal 100.0
92+
math.pow (2.0, 3.0) |> equal 8.0
93+
math.pow (10.0, 2.0) |> equal 100.0
9494

9595
[<Fact>]
9696
let ``test sin works`` () =
@@ -118,7 +118,7 @@ let ``test atan works`` () =
118118

119119
[<Fact>]
120120
let ``test atan2 works`` () =
121-
math.atan2 0.0 1.0 |> equal 0.0
121+
math.atan2 (0.0, 1.0) |> equal 0.0
122122

123123
[<Fact>]
124124
let ``test pi constant works`` () =
@@ -182,7 +182,7 @@ let ``test perm works`` () =
182182

183183
[<Fact>]
184184
let ``test dist works`` () =
185-
math.dist [| 0.0; 0.0 |] [| 3.0; 4.0 |] |> equal 5.0
185+
math.dist ([| 0.0; 0.0 |], [| 3.0; 4.0 |]) |> equal 5.0
186186

187187
[<Fact>]
188188
let ``test cosh works`` () =

0 commit comments

Comments
 (0)