From 868bee8a068c3843f79bcc4a9b3d4a206a52ebd0 Mon Sep 17 00:00:00 2001 From: Mikko Ahlroth Date: Sun, 4 Feb 2024 09:43:26 +0200 Subject: [PATCH] Simplify design --- src/bigi.gleam | 72 +++++++++----------------------------------------- 1 file changed, 12 insertions(+), 60 deletions(-) diff --git a/src/bigi.gleam b/src/bigi.gleam index 27922b5..b9a5af4 100644 --- a/src/bigi.gleam +++ b/src/bigi.gleam @@ -1,93 +1,45 @@ -pub opaque type Bigi { - Bigi(data: BigInt) -} - -type BigInt - -pub fn from_int(int: Int) { - Bigi(bigint_from(int)) -} - -pub fn to_int(bigi: Bigi) { - bigint_to(bigi.data) -} - -pub fn to_string(bigi: Bigi) { - bigint_to_string(bigi.data) -} - -pub fn zero() { - Bigi(bigint_zero()) -} - -pub fn add(a: Bigi, b: Bigi) { - Bigi(bigint_add(a.data, b.data)) -} - -pub fn subtract(a: Bigi, b: Bigi) { - Bigi(bigint_subtract(a.data, b.data)) -} - -pub fn multiply(a: Bigi, b: Bigi) { - Bigi(bigint_multiply(a.data, b.data)) -} - -pub fn divide(a: Bigi, b: Bigi) { - Bigi(bigint_divide(a.data, b.data)) -} - -pub fn remainder(a: Bigi, b: Bigi) { - Bigi(bigint_remainder(a.data, b.data)) -} - -pub fn modulo(a: Bigi, b: Bigi) { - Bigi(bigint_modulo(a.data, b.data)) -} - -pub fn power(a: Bigi, b: Bigi) { - Bigi(bigint_power(a.data, b.data)) -} +pub type BigInt @external(erlang, "bigi_ffi", "from") @external(javascript, "./bigi_ffi.mjs", "from") -fn bigint_from(int: Int) -> BigInt +pub fn from_int(int: Int) -> BigInt @external(erlang, "bigi_ffi", "to") @external(javascript, "./bigi_ffi.mjs", "to") -fn bigint_to(bigint: BigInt) -> Result(Int, Nil) +pub fn to_int(bigint: BigInt) -> Result(Int, Nil) @external(erlang, "bigi_ffi", "to_string") @external(javascript, "./bigi_ffi.mjs", "to_string") -fn bigint_to_string(bigint: BigInt) -> String +pub fn to_string(bigint: BigInt) -> String @external(erlang, "bigi_ffi", "zero") @external(javascript, "./bigi_ffi.mjs", "zero") -fn bigint_zero() -> BigInt +pub fn zero() -> BigInt @external(erlang, "bigi_ffi", "add") @external(javascript, "./bigi_ffi.mjs", "add") -fn bigint_add(a: BigInt, b: BigInt) -> BigInt +pub fn add(a: BigInt, b: BigInt) -> BigInt @external(erlang, "bigi_ffi", "subtract") @external(javascript, "./bigi_ffi.mjs", "subtract") -fn bigint_subtract(a: BigInt, b: BigInt) -> BigInt +pub fn subtract(a: BigInt, b: BigInt) -> BigInt @external(erlang, "bigi_ffi", "multiply") @external(javascript, "./bigi_ffi.mjs", "multiply") -fn bigint_multiply(a: BigInt, b: BigInt) -> BigInt +pub fn multiply(a: BigInt, b: BigInt) -> BigInt @external(erlang, "bigi_ffi", "divide") @external(javascript, "./bigi_ffi.mjs", "divide") -fn bigint_divide(a: BigInt, b: BigInt) -> BigInt +pub fn divide(a: BigInt, b: BigInt) -> BigInt @external(erlang, "bigi_ffi", "remainder") @external(javascript, "./bigi_ffi.mjs", "remainder") -fn bigint_remainder(a: BigInt, b: BigInt) -> BigInt +pub fn remainder(a: BigInt, b: BigInt) -> BigInt @external(erlang, "bigi_ffi", "modulo") @external(javascript, "./bigi_ffi.mjs", "modulo") -fn bigint_modulo(a: BigInt, b: BigInt) -> BigInt +pub fn modulo(a: BigInt, b: BigInt) -> BigInt @external(erlang, "bigi_ffi", "power") @external(javascript, "./bigi_ffi.mjs", "power") -fn bigint_power(a: BigInt, b: BigInt) -> BigInt +pub fn power(a: BigInt, b: BigInt) -> BigInt