From ebd0518392ab5835fe050d4824787eefa52c5177 Mon Sep 17 00:00:00 2001
From: NicklasXYZ <18580183+NicklasXYZ@users.noreply.github.com>
Date: Mon, 12 Aug 2024 23:32:37 +0200
Subject: [PATCH 1/3] update workflows
---
.github/workflows/release.yml | 2 +-
.github/workflows/test.yml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 3ce4599..bc94906 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -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:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 98c5e59..e8e6d9d 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -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:
From fc5dc23aec6bd5105a85142a18371a44c9d6d1f4 Mon Sep 17 00:00:00 2001
From: NicklasXYZ <18580183+NicklasXYZ@users.noreply.github.com>
Date: Tue, 13 Aug 2024 00:09:11 +0200
Subject: [PATCH 2/3] Add is_divisible/is_multiple predicate functions
---
src/gleam_community/maths/predicates.gleam | 124 ++++++++++++++++++
.../maths/predicates_test.gleam | 27 ++++
2 files changed, 151 insertions(+)
diff --git a/src/gleam_community/maths/predicates.gleam b/src/gleam_community/maths/predicates.gleam
index ac147a6..5784328 100644
--- a/src/gleam_community/maths/predicates.gleam
+++ b/src/gleam_community/maths/predicates.gleam
@@ -30,6 +30,7 @@
//// * [`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)
@@ -464,3 +465,126 @@ fn powmod_with_check(base: Int, exponent: Int, modulus: Int) -> Int {
_, _ -> { base * powmod_with_check(base, exponent - 1, modulus) } % modulus
}
}
+
+///
+///
+/// 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$$.
+///
+///
+/// Example:
+///
+/// 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)
+/// }
+///
+///
+///
+///
+pub fn is_between(x: Float, lower: Float, upper: Float) -> Bool {
+ lower <. x && x <. upper
+}
+
+///
+///
+/// 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
+///
+/// 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$$.
+///
+///
+///
+///
+/// Example:
+///
+/// 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)
+/// }
+///
+///
+///
+///
+pub fn is_divisible(n: Int, d: Int) -> Bool {
+ n % d == 0
+}
+
+///
+///
+/// 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
+///
+/// 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.
+///
+///
+///
+///
+/// Example:
+///
+/// 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)
+/// }
+///
+///
+///
+///
+pub fn is_multiple(m: Int, k: Int) -> Bool {
+ m % k == 0
+}
diff --git a/test/gleam_community/maths/predicates_test.gleam b/test/gleam_community/maths/predicates_test.gleam
index 2244a9a..fcae19c 100644
--- a/test/gleam_community/maths/predicates_test.gleam
+++ b/test/gleam_community/maths/predicates_test.gleam
@@ -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)
+}
From b1b5ec0692598c36061fdef30d2a58e33702f43a Mon Sep 17 00:00:00 2001
From: NicklasXYZ <18580183+NicklasXYZ@users.noreply.github.com>
Date: Tue, 13 Aug 2024 00:11:58 +0200
Subject: [PATCH 3/3] update predicate module docs
---
src/gleam_community/maths/predicates.gleam | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/gleam_community/maths/predicates.gleam b/src/gleam_community/maths/predicates.gleam
index 5784328..940f3a9 100644
--- a/src/gleam_community/maths/predicates.gleam
+++ b/src/gleam_community/maths/predicates.gleam
@@ -35,6 +35,8 @@
//// * [`is_perfect`](#is_perfect)
//// * [`is_even`](#is_even)
//// * [`is_odd`](#is_odd)
+//// * [`is_divisible`](#is_divisible)
+//// * [`is_multiple`](#is_multiple)
//// * [`is_prime`](#is_prime)
////