Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ All notable changes to this project will be documented in this file.
### 🐞 Bug Fixes

* 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.
* Fix `math.copysign` binding: `y` parameter was incorrectly typed as `int`, now correctly `float`
* Fix `math.fmod` binding: parameters were incorrectly typed as `int -> int -> int`, now correctly `float * float -> float`
* Fix `math.comb`, `math.pow`, `math.atan2`, `math.dist` bindings: converted curried parameter syntax to tupled for consistency

### ✨ Enhancements

Expand Down
12 changes: 6 additions & 6 deletions src/stdlib/Math.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ type IExports =
abstract ceil: x: float -> int
/// Return the number of ways to choose k items from n items (n choose k)
/// See https://docs.python.org/3/library/math.html#math.comb
abstract comb: n: int -> k: int -> int
abstract comb: n: int * k: int -> int
/// Return a float with the magnitude of x and the sign of y
/// See https://docs.python.org/3/library/math.html#math.copysign
abstract copysign: x: float -> y: int -> float
abstract copysign: x: float * y: float -> float
/// Return the absolute value of x
/// See https://docs.python.org/3/library/math.html#math.fabs
abstract fabs: x: float -> float
Expand All @@ -59,7 +59,7 @@ type IExports =
abstract floor: x: float -> int
/// Return the floating-point remainder of x / y
/// See https://docs.python.org/3/library/math.html#math.fmod
abstract fmod: x: int -> y: int -> int
abstract fmod: x: float * y: float -> float
/// Return an accurate floating-point sum of values in the iterable
/// See https://docs.python.org/3/library/math.html#math.fsum
abstract fsum: iterable: float seq -> float
Expand Down Expand Up @@ -132,7 +132,7 @@ type IExports =
abstract log10: x: float -> float
/// Return x raised to the power y
/// See https://docs.python.org/3/library/math.html#math.pow
abstract pow: x: float -> y: float -> float
abstract pow: x: float * y: float -> float
/// Return the square root of x
/// See https://docs.python.org/3/library/math.html#math.sqrt
abstract sqrt: x: float -> float
Expand All @@ -152,7 +152,7 @@ type IExports =
abstract atan: x: float -> float
/// Return the arc tangent of y/x in radians
/// See https://docs.python.org/3/library/math.html#math.atan2
abstract atan2: y: float -> x: float -> float
abstract atan2: y: float * x: float -> float
/// Return the cosine of x radians
/// See https://docs.python.org/3/library/math.html#math.cos
abstract cos: x: float -> float
Expand Down Expand Up @@ -218,7 +218,7 @@ type IExports =

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

/// Mathematical functions
[<ImportAll("math")>]
Expand Down
20 changes: 10 additions & 10 deletions test/TestMath.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ let ``test floor works`` () =

[<Fact>]
let ``test comb works`` () =
math.comb 5 2 |> equal 10
math.comb 10 3 |> equal 120
math.comb (5, 2) |> equal 10
math.comb (10, 3) |> equal 120

[<Fact>]
let ``test copysign works`` () =
math.copysign 1.0 -1 |> equal -1.0
math.copysign -1.0 1 |> equal 1.0
math.copysign (1.0, -1.0) |> equal -1.0
math.copysign (-1.0, 1.0) |> equal 1.0

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

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

[<Fact>]
let ``test gcd works`` () =
Expand Down Expand Up @@ -89,8 +89,8 @@ let ``test log10 works`` () =

[<Fact>]
let ``test pow works`` () =
math.pow 2.0 3.0 |> equal 8.0
math.pow 10.0 2.0 |> equal 100.0
math.pow (2.0, 3.0) |> equal 8.0
math.pow (10.0, 2.0) |> equal 100.0

[<Fact>]
let ``test sin works`` () =
Expand Down Expand Up @@ -118,7 +118,7 @@ let ``test atan works`` () =

[<Fact>]
let ``test atan2 works`` () =
math.atan2 0.0 1.0 |> equal 0.0
math.atan2 (0.0, 1.0) |> equal 0.0

[<Fact>]
let ``test pi constant works`` () =
Expand Down Expand Up @@ -182,7 +182,7 @@ let ``test perm works`` () =

[<Fact>]
let ``test dist works`` () =
math.dist [| 0.0; 0.0 |] [| 3.0; 4.0 |] |> equal 5.0
math.dist ([| 0.0; 0.0 |], [| 3.0; 4.0 |]) |> equal 5.0

[<Fact>]
let ``test cosh works`` () =
Expand Down
Loading