mirror of
https://github.com/sigmasternchen/gleam-community-maths
synced 2025-03-15 07:59:01 +00:00
Merge pull request #25 from NicklasXYZ/main
Add new predicate functions + update workflow
This commit is contained in:
commit
7fd917f43c
4 changed files with 155 additions and 2 deletions
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
@ -14,7 +14,7 @@ jobs:
|
|||
- uses: erlef/setup-beam@v1
|
||||
with:
|
||||
otp-version: "26.2"
|
||||
gleam-version: "1.0.0"
|
||||
gleam-version: "1.4.1"
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
|
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -20,7 +20,7 @@ jobs:
|
|||
- uses: erlef/setup-beam@v1
|
||||
with:
|
||||
otp-version: "26.2"
|
||||
gleam-version: "1.0.0"
|
||||
gleam-version: "1.4.1"
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
|
|
|
@ -30,10 +30,13 @@
|
|||
//// * [`is_close`](#is_close)
|
||||
//// * [`list_all_close`](#all_close)
|
||||
//// * [`is_fractional`](#is_fractional)
|
||||
//// * [`is_between`](#is_between)
|
||||
//// * [`is_power`](#is_power)
|
||||
//// * [`is_perfect`](#is_perfect)
|
||||
//// * [`is_even`](#is_even)
|
||||
//// * [`is_odd`](#is_odd)
|
||||
//// * [`is_divisible`](#is_divisible)
|
||||
//// * [`is_multiple`](#is_multiple)
|
||||
//// * [`is_prime`](#is_prime)
|
||||
////
|
||||
|
||||
|
@ -464,3 +467,126 @@ fn powmod_with_check(base: Int, exponent: Int, modulus: Int) -> Int {
|
|||
_, _ -> { base * powmod_with_check(base, exponent - 1, modulus) } % modulus
|
||||
}
|
||||
}
|
||||
|
||||
/// <div style="text-align: right;">
|
||||
/// <a href="https://github.com/gleam-community/maths/issues">
|
||||
/// <small>Spot a typo? Open an issue!</small>
|
||||
/// </a>
|
||||
/// </div>
|
||||
///
|
||||
/// A function that tests whether a given real number $$x \in \mathbb{R}$$ is strictly
|
||||
/// between two other real numbers, $$a,b \in \mathbb{R}$$, such that $$a < x < b$$.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example:</summary>
|
||||
///
|
||||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example() {
|
||||
/// predicates.is_between(5.5, 5.0, 6.0)
|
||||
/// |> should.equal(True)
|
||||
///
|
||||
/// predicates.is_between(5.0, 5.0, 6.0)
|
||||
/// |> should.equal(False)
|
||||
///
|
||||
/// predicates.is_between(6.0, 5.0, 6.0)
|
||||
/// |> should.equal(False)
|
||||
/// }
|
||||
/// </details>
|
||||
///
|
||||
/// <div style="text-align: right;">
|
||||
/// <a href="#">
|
||||
/// <small>Back to top ↑</small>
|
||||
/// </a>
|
||||
/// </div>
|
||||
///
|
||||
pub fn is_between(x: Float, lower: Float, upper: Float) -> Bool {
|
||||
lower <. x && x <. upper
|
||||
}
|
||||
|
||||
/// <div style="text-align: right;">
|
||||
/// <a href="https://github.com/gleam-community/maths/issues">
|
||||
/// <small>Spot a typo? Open an issue!</small>
|
||||
/// </a>
|
||||
/// </div>
|
||||
///
|
||||
/// A function that tests whether a given integer $$n \in \mathbb{Z}$$ is divisible by another
|
||||
/// integer $$d \in \mathbb{Z}$$, such that $$n \mod d = 0$$.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Details</summary>
|
||||
///
|
||||
/// For example:
|
||||
/// - $$n = 10$$ is divisible by $$d = 2$$ because $$10 \mod 2 = 0$$.
|
||||
/// - $$n = 7$$ is not divisible by $$d = 3$$ because $$7 \mod 3 \neq 0$$.
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example:</summary>
|
||||
///
|
||||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example() {
|
||||
/// predicates.is_divisible(10, 2)
|
||||
/// |> should.equal(True)
|
||||
///
|
||||
/// predicates.is_divisible(7, 3)
|
||||
/// |> should.equal(False)
|
||||
/// }
|
||||
/// </details>
|
||||
///
|
||||
/// <div style="text-align: right;">
|
||||
/// <a href="#">
|
||||
/// <small>Back to top ↑</small>
|
||||
/// </a>
|
||||
/// </div>
|
||||
///
|
||||
pub fn is_divisible(n: Int, d: Int) -> Bool {
|
||||
n % d == 0
|
||||
}
|
||||
|
||||
/// <div style="text-align: right;">
|
||||
/// <a href="https://github.com/gleam-community/maths/issues">
|
||||
/// <small>Spot a typo? Open an issue!</small>
|
||||
/// </a>
|
||||
/// </div>
|
||||
///
|
||||
/// A function that tests whether a given integer $$m \in \mathbb{Z}$$ is a multiple of another
|
||||
/// integer $$k \in \mathbb{Z}$$, such that $$m = k \times q \quad q \in \mathbb{Z}$$.
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Details</summary>
|
||||
///
|
||||
/// For example:
|
||||
/// - $$m = 15$$ is a multiple of $$k = 5$$ because $$15 = 5 \times 3$$.
|
||||
/// - $$m = 14$$ is not a multiple of $$k = 5$$ because $$14 \div 5$$ does not yield an integer quotient.
|
||||
///
|
||||
/// </details>
|
||||
///
|
||||
/// <details>
|
||||
/// <summary>Example:</summary>
|
||||
///
|
||||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example() {
|
||||
/// predicates.is_multiple(15, 5)
|
||||
/// |> should.equal(True)
|
||||
///
|
||||
/// predicates.is_multiple(14, 5)
|
||||
/// |> should.equal(False)
|
||||
/// }
|
||||
/// </details>
|
||||
///
|
||||
/// <div style="text-align: right;">
|
||||
/// <a href="#">
|
||||
/// <small>Back to top ↑</small>
|
||||
/// </a>
|
||||
/// </div>
|
||||
///
|
||||
pub fn is_multiple(m: Int, k: Int) -> Bool {
|
||||
m % k == 0
|
||||
}
|
||||
|
|
|
@ -174,3 +174,30 @@ pub fn int_is_prime_test() {
|
|||
predicates.is_prime(1105)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
||||
pub fn is_between_test() {
|
||||
predicates.is_between(5.5, 5.0, 6.0)
|
||||
|> should.equal(True)
|
||||
|
||||
predicates.is_between(5.0, 5.0, 6.0)
|
||||
|> should.equal(False)
|
||||
|
||||
predicates.is_between(6.0, 5.0, 6.0)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
||||
pub fn is_divisible_test() {
|
||||
predicates.is_divisible(10, 2)
|
||||
|> should.equal(True)
|
||||
|
||||
predicates.is_divisible(7, 3)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
||||
pub fn is_multiple_test() {
|
||||
predicates.is_multiple(15, 5)
|
||||
|> should.equal(True)
|
||||
|
||||
predicates.is_multiple(14, 5)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue