Change the argument order of comparisons

This commit is contained in:
Mikko Ahlroth 2024-04-11 18:35:52 +03:00
parent 987839dade
commit f05525b3ba
8 changed files with 19 additions and 12 deletions

View file

@ -1,3 +1,9 @@
2.0.0
-----
* Changed the argument order of interface.compare, thus also changing the argument order
of all comparisons in the builtins. The new order matches int.compare from the stdlib.
1.0.0
-----

View file

@ -171,7 +171,7 @@ pub fn mvp_test() {
let assert Ok(a) = interface.from_bigint(bigi.from_int(2007), mvp.iface)
let assert Ok(b) = interface.from_bigint(bigi.from_int(2009), mvp.iface)
let c = interface.compare(a, b, mvp.iface)
should.equal(c, order.Gt)
should.equal(c, order.Lt)
}
```
@ -231,7 +231,7 @@ pub fn mvp2_test() {
let assert Ok(a) = mvp2.from_bigint(bigi.from_int(2007))
let assert Ok(b) = mvp2.from_bigint(bigi.from_int(2009))
let c = mvp2.compare(a, b)
should.equal(c, order.Gt)
should.equal(c, order.Lt)
}
pub fn mvp2_add_test() {

View file

@ -1,5 +1,5 @@
name = "ranged_int"
version = "1.0.0"
version = "2.0.0"
# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
@ -14,7 +14,7 @@ repository = { type = "gitlab", user = "Nicd", repo = "ranged_int" }
[dependencies]
gleam_stdlib = "~> 0.34 or ~> 1.0"
bigi = "~> 2.0"
bigi = "~> 3.0"
[dev-dependencies]
gleeunit = "~> 1.0"

View file

@ -2,12 +2,12 @@
# You typically do not need to edit this file
packages = [
{ name = "bigi", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "bigi", source = "hex", outer_checksum = "E7841470F475D20B2EC2D4CB1167A8893AE943B6541809DCAB9D95FB471FDCDB" },
{ name = "bigi", version = "3.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "bigi", source = "hex", outer_checksum = "FFDFC542A5146C535AE09AB9A642D652AD8B018509CDA70E1D09741EDB64FBF7" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
]
[requirements]
bigi = { version = "~> 2.0" }
bigi = { version = "~> 3.0" }
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }

View file

@ -90,7 +90,8 @@ pub fn from_bigint(
}
}
/// Compare two ranged integers.
/// Compare two ranged integers, returning an order that denotes if `int1` is
/// lower, bigger than, or equal to `int2`.
pub fn compare(
int1: a,
int2: a,

View file

@ -25,11 +25,11 @@ pub type LimitCheck {
/// Check the value against the limits.
pub fn check_limits(value: BigInt, min min: Limit, max max: Limit) -> LimitCheck {
let max_diff = diff(max, value)
case bigi.compare(bigi.zero(), max_diff) {
case bigi.compare(max_diff, bigi.zero()) {
order.Gt -> Overflow(max_diff)
order.Eq | order.Lt -> {
let min_diff = diff(min, value)
case bigi.compare(bigi.zero(), min_diff) {
case bigi.compare(min_diff, bigi.zero()) {
order.Lt -> Underflow(bigi.multiply(min_diff, bigi.from_int(-1)))
order.Eq | order.Gt -> NoOverflow
}

View file

@ -8,7 +8,7 @@ pub fn mvp2_test() {
let assert Ok(a) = mvp2.from_bigint(bigi.from_int(2007))
let assert Ok(b) = mvp2.from_bigint(bigi.from_int(2009))
let c = mvp2.compare(a, b)
should.equal(c, order.Gt)
should.equal(c, order.Lt)
}
pub fn mvp2_add_test() {
@ -18,7 +18,7 @@ pub fn mvp2_add_test() {
should.equal(c, Error(utils.WouldOverflow(bigi.from_int(1))))
should.equal(
mvp2.overflow(c)
|> mvp2.to_bigint(),
|> mvp2.to_bigint(),
bigi.from_int(2007),
)
}

View file

@ -9,7 +9,7 @@ pub fn mvp_test() {
let assert Ok(a) = interface.from_bigint(bigi.from_int(2007), mvp.iface)
let assert Ok(b) = interface.from_bigint(bigi.from_int(2009), mvp.iface)
let c = interface.compare(a, b, mvp.iface)
should.equal(c, order.Gt)
should.equal(c, order.Lt)
}
pub fn mvp_add_test() {