diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c89bbf5..4f2cd62 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +3.0.0 +----- + +* Changed bigi.compare argument order to match int.compare from stdlib. + 2.1.0 ----- diff --git a/gleam.toml b/gleam.toml index ac7b608..ba34ebb 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "bigi" -version = "2.1.0" +version = "3.0.0" # Fill out these fields if you intend to generate HTML documentation or publish # your project to the Hex package manager. diff --git a/src/bigi.gleam b/src/bigi.gleam index e15b30e..578c9fb 100644 --- a/src/bigi.gleam +++ b/src/bigi.gleam @@ -46,8 +46,8 @@ pub fn to_int(bigint: BigInt) -> Result(Int, Nil) @external(javascript, "./bigi_ffi.mjs", "to_string") pub fn to_string(bigint: BigInt) -> String -/// Compare two big integers, returning an order that denotes if `b` is lower, -/// bigger than, or equal to `a`. +/// Compare two big integers, returning an order that denotes if `a` is lower, +/// bigger than, or equal to `b`. @external(erlang, "bigi_ffi", "compare") @external(javascript, "./bigi_ffi.mjs", "compare") pub fn compare(a: BigInt, with b: BigInt) -> order.Order @@ -147,7 +147,7 @@ pub fn decode(dyn: dynamic.Dynamic) -> Result(BigInt, dynamic.DecodeErrors) fn get_digit(bigint: BigInt, digits: List(Int), divisor: BigInt) { case compare(bigint, divisor) { - order.Gt -> { + order.Lt -> { let assert Ok(digit) = to_int(bigint) [digit, ..digits] } diff --git a/src/bigi_ffi.erl b/src/bigi_ffi.erl index fc25066..b4da818 100644 --- a/src/bigi_ffi.erl +++ b/src/bigi_ffi.erl @@ -31,8 +31,8 @@ to(BigInt) -> {ok, BigInt}. zero() -> 0. -compare(A, B) when A < B -> gt; -compare(A, B) when A > B -> lt; +compare(A, B) when A < B -> lt; +compare(A, B) when A > B -> gt; compare(_, _) -> eq. add(A, B) -> A + B. diff --git a/src/bigi_ffi.mjs b/src/bigi_ffi.mjs index 80c6134..3b381de 100644 --- a/src/bigi_ffi.mjs +++ b/src/bigi_ffi.mjs @@ -32,9 +32,9 @@ export function zero() { export function compare(a, b) { if (a < b) { - return new Gt(); - } else if (a > b) { return new Lt(); + } else if (a > b) { + return new Gt(); } else { return new Eq(); } diff --git a/test/bigi_test.gleam b/test/bigi_test.gleam index 1809a04..7ec4a76 100644 --- a/test/bigi_test.gleam +++ b/test/bigi_test.gleam @@ -22,8 +22,8 @@ pub fn zero_test() { } pub fn compare_test() { - should.equal(bigi.compare(bigi.from_int(1), bigi.from_int(2)), order.Gt) - should.equal(bigi.compare(bigi.from_int(2), bigi.from_int(1)), order.Lt) + should.equal(bigi.compare(bigi.from_int(1), bigi.from_int(2)), order.Lt) + should.equal(bigi.compare(bigi.from_int(2), bigi.from_int(1)), order.Gt) should.equal(bigi.compare(bigi.from_int(1), bigi.from_int(1)), order.Eq) }