diff --git a/asconfig.json b/asconfig.json index 00cca64..877b9f3 100644 --- a/asconfig.json +++ b/asconfig.json @@ -6,6 +6,7 @@ "debug": false, "noExportMemory": true, "optimize": true, + "converge": true, "noAssert": true } } diff --git a/assembly/index.ts b/assembly/index.ts index db8507f..4e23846 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -1,3 +1,3 @@ export function f64_pow(x: f64, y: f64): f64 { - return Math.pow(x, y); + return inline.always(Math.pow(x, y)); } diff --git a/index.js b/index.js index 3079171..11eaaff 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,3 @@ import { MathWasmBase64 } from "./build/math.js"; -const exports = (await WebAssembly.instantiate(Buffer.from(MathWasmBase64, "base64"))).instance.exports; - -export function f64_pow(value, exponent) { - return exports.f64_pow(value, exponent); -} +export const {f64_pow} = (await WebAssembly.instantiateStreaming(fetch(MathWasmBase64))).instance.exports; diff --git a/scripts/postbuild.js b/scripts/postbuild.js index 9cea09d..ff967a7 100644 --- a/scripts/postbuild.js +++ b/scripts/postbuild.js @@ -2,4 +2,4 @@ import { readFileSync, writeFileSync } from "fs"; const base64String = readFileSync("build/math.wasm", "base64"); -writeFileSync("build/math.js", `export const MathWasmBase64 = "${base64String}";`); +writeFileSync("build/math.js", `export const MathWasmBase64 = "data:application/wasm;base64,${base64String}";`); diff --git a/test/index.js b/test/index.js index 084f564..1d940b7 100644 --- a/test/index.js +++ b/test/index.js @@ -2,4 +2,4 @@ import { f64_pow } from "../index.js"; import assert from "assert"; assert(f64_pow(2, 2) === 4, "2^2 == 4"); -assert(f64_pow(10, -5) === 0.00001, "2^2 == 4"); +assert(f64_pow(10, -5) === 0.00001, "10^-5 == 0.00001");