diff --git a/src/gleam_community/maths/float.gleam b/src/gleam_community/maths/float.gleam index 6fbd311..83eeb6b 100644 --- a/src/gleam_community/maths/float.gleam +++ b/src/gleam_community/maths/float.gleam @@ -489,8 +489,8 @@ if erlang { } if javascript { - external fn do_to_int(Float) -> Int = - "../floatx.mjs" "trunc" + external fn do_truncate_float(Float) -> Float = + "../../maths.mjs" "truncate" } // Rounding mode: Down / Floor @@ -505,7 +505,7 @@ if erlang { if javascript { external fn do_floor(Float) -> Float = - "../floatx.mjs" "floor" + "../../maths.mjs" "floor" } // Rounding mode: Up / Ceiling @@ -520,7 +520,7 @@ if erlang { if javascript { external fn do_ceiling(Float) -> Float = - "../floatx.mjs" "ceil" + "../../maths.mjs" "ceiling" } ///
@@ -568,7 +568,7 @@ if erlang { if javascript { external fn do_to_int(Float) -> Int = - "../floatx.mjs" "to_int" + "../../maths.mjs" "truncate" } ///
@@ -629,7 +629,7 @@ if erlang { if javascript { external fn do_acos(Float) -> Float = - "../floatx.mjs" "acos" + "../../maths.mjs" "acos" } ///
@@ -687,7 +687,7 @@ if erlang { if javascript { external fn do_acosh(Float) -> Float = - "../floatx.mjs" "acosh" + "../../maths.mjs" "acosh" } ///
@@ -748,7 +748,7 @@ if erlang { if javascript { external fn do_asin(Float) -> Float = - "../floatx.mjs" "asin" + "../../maths.mjs" "asin" } ///
@@ -795,7 +795,7 @@ if erlang { if javascript { external fn do_asinh(Float) -> Float = - "../floatx.mjs" "asinh" + "../../maths.mjs" "asinh" } ///
@@ -842,7 +842,7 @@ if erlang { if javascript { external fn do_atan(Float) -> Float = - "../floatx.mjs" "atan" + "../../maths.mjs" "atan" } ///
@@ -898,7 +898,7 @@ if erlang { if javascript { external fn do_atan2(Float, Float) -> Float = - "../floatx.mjs" "atan2" + "../../maths.mjs" "atan2" } ///
@@ -959,7 +959,7 @@ if erlang { if javascript { external fn do_atanh(Float) -> Float = - "../floatx.mjs" "atanh" + "../../maths.mjs" "atanh" } ///
@@ -1009,7 +1009,7 @@ if erlang { if javascript { external fn do_cos(Float) -> Float = - "../floatx.mjs" "cos" + "../../maths.mjs" "cos" } ///
@@ -1057,7 +1057,7 @@ if erlang { if javascript { external fn do_cosh(Float) -> Float = - "../floatx.mjs" "cosh" + "../../maths.mjs" "cosh" } ///
@@ -1105,7 +1105,7 @@ if erlang { if javascript { external fn do_exponential(Float) -> Float = - "../floatx.mjs" "exp" + "../../maths.mjs" "exponential" } ///
@@ -1236,7 +1236,7 @@ if erlang { if javascript { external fn do_natural_logarithm(Float) -> Float = - "../floatx.mjs" "log" + "../../maths.mjs" "logarithm" } ///
@@ -1297,7 +1297,7 @@ if erlang { if javascript { external fn do_logarithm_10(Float) -> Float = - "../floatx.mjs" "log10" + "../../maths.mjs" "logarithm_10" } ///
@@ -1358,7 +1358,7 @@ if erlang { if javascript { external fn do_logarithm_2(Float) -> Float = - "../floatx.mjs" "log2" + "../../maths.mjs" "logarithm_2" } ///
@@ -1432,7 +1432,7 @@ if erlang { if javascript { external fn do_power(Float, Float) -> Float = - "../floatx.mjs" "pow" + "../../maths.mjs" "power" } ///
@@ -1680,7 +1680,7 @@ if erlang { if javascript { external fn do_sin(Float) -> Float = - "../floatx.mjs" "sin" + "../../maths.mjs" "sin" } ///
@@ -1729,7 +1729,7 @@ if erlang { if javascript { external fn do_sinh(Float) -> Float = - "../floatx.mjs" "sinh" + "../../maths.mjs" "sinh" } ///
@@ -1777,7 +1777,7 @@ if erlang { if javascript { external fn do_tan(Float) -> Float = - "../floatx.mjs" "tan" + "../../maths.mjs" "tan" } ///
@@ -1830,7 +1830,7 @@ if erlang { if javascript { external fn do_tanh(Float) -> Float = - "../floatx.mjs" "tanh" + "../../maths.mjs" "tanh" } ///
@@ -2036,7 +2036,7 @@ if erlang { if javascript { external fn do_sign(Float) -> Float = - "../floatx.mjs" "sign" + "../../maths.mjs" "sign" } ///
@@ -2271,7 +2271,7 @@ if erlang { if javascript { external fn do_pi() -> Float = - "../floatx.mjs" "pi" + "../../maths.mjs" "pi" } ///
diff --git a/src/gleam_community/maths/int.gleam b/src/gleam_community/maths/int.gleam index e77cc83..8426686 100644 --- a/src/gleam_community/maths/int.gleam +++ b/src/gleam_community/maths/int.gleam @@ -194,7 +194,7 @@ if erlang { if javascript { external fn do_sign(Int) -> Int = - "../intx.mjs" "sign" + "../../maths.mjs" "sign" } ///
diff --git a/src/maths.mjs b/src/maths.mjs new file mode 100644 index 0000000..5c5ab31 --- /dev/null +++ b/src/maths.mjs @@ -0,0 +1,95 @@ +export function sin(float) { + return Math.sin(float) +} + +export function pi() { + return Math.PI +} + +export function acos(float) { + return Math.acos(float) +} + +export function acosh(float) { + return Math.acosh(float) +} + +export function asin(float) { + return Math.asin(float) +} + +export function asinh(float) { + return Math.asinh(float) +} + +export function atan(float) { + return Math.atan(float) +} + +export function tan(float) { + return Math.tan(float) +} + +export function atan2(floaty, floatx) { + return Math.atan2(floaty, floatx) +} + +export function atanh(float) { + return Math.atanh(float) +} + +export function cos(float) { + return Math.cos(float) +} + +export function cosh(float) { + return Math.cosh(float) +} + +export function exponential(float) { + return Math.exp(float) +} + +export function ceiling(float) { + return Math.ceil(float) +} + +export function floor(float) { + return Math.floor(float) +} + +export function power(base, exponent) { + return Math.pow(base, exponent) +} + +export function logarithm(float) { + return Math.log(float) +} + +export function logarithm_10(float) { + return Math.log10(float) +} + +export function logarithm_2(float) { + return Math.log2(float) +} + +export function sinh(float) { + return Math.sinh(float) +} + +export function tanh(float) { + return Math.tanh(float) +} + +export function sign(float) { + return Math.sign(float) +} + +export function truncate(float) { + return Math.trunc(float) +} + +export function to_int(float) { + return Math.trunc(float) +} diff --git a/test/gleam_community_maths_test_ffi.mjs b/test/gleam_community_maths_test_ffi.mjs index 9468767..d12c906 100755 --- a/test/gleam_community_maths_test_ffi.mjs +++ b/test/gleam_community_maths_test_ffi.mjs @@ -1,6 +1,6 @@ import { opendir } from "fs/promises"; -const dir = "build/dev/javascript/gleam_community_maths/dist/gleam/"; +const dir = "build/dev/javascript/gleam_community_maths/gleam/"; export async function main() { console.log("Running tests...");