Change bigi.compare argument order
This commit is contained in:
parent
6583d85edf
commit
5c07aad495
6 changed files with 15 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
|||
3.0.0
|
||||
-----
|
||||
|
||||
* Changed bigi.compare argument order to match int.compare from stdlib.
|
||||
|
||||
2.1.0
|
||||
-----
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue