Skip to content

Browser support + marginally smaller modules #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"debug": false,
"noExportMemory": true,
"optimize": true,
"converge": true,
"noAssert": true
}
}
2 changes: 1 addition & 1 deletion assembly/index.ts
Original file line number Diff line number Diff line change
@@ -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));
}
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion scripts/postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}";`);
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");