Skip to content

Commit 340db5d

Browse files
committed
first commit
0 parents  commit 340db5d

File tree

12 files changed

+146
-0
lines changed

12 files changed

+146
-0
lines changed

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 20
16+
- run: npm ci
17+
- run: npm run build
18+
- run: npm run test
19+
- run: npm version $(echo "${GITHUB_REF}" | sed 's/refs\/tags\///') --git-tag-version false
20+
- run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc
21+
env:
22+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
23+
- run: npm publish

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/build

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# as-math

asconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"options": {
3+
"outFile": "build/math.wasm",
4+
"textFile": "build/math.wat",
5+
"sourceMap": false,
6+
"debug": false,
7+
"noExportMemory": true,
8+
"optimize": true,
9+
"noAssert": true
10+
}
11+
}

assembly/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function f64_pow(x: f64, y: f64): f64 {
2+
return Math.pow(x, y);
3+
}

assembly/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": [
4+
"./**/*.ts"
5+
]
6+
}

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare function f64_pow(value: f64, exponent: f64): f64;

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { MathWasmBase64 } from "./build/math.js";
2+
3+
const exports = (await WebAssembly.instantiate(Buffer.from(MathWasmBase64, "base64"))).instance.exports;
4+
5+
export function f64_pow(value, exponent) {
6+
return exports.f64_pow(value, exponent);
7+
}

package-lock.json

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "as-float",
3+
"version": "0.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"build": "asc assembly/index.ts && node scripts/postbuild.js",
7+
"test": "node test/index.js"
8+
},
9+
"type": "module",
10+
"author": "Congcong Cai <[email protected]>",
11+
"license": "MIT",
12+
"description": "",
13+
"devDependencies": {
14+
"assemblyscript": "^0.27.36"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/HerrCai0907/as-float"
19+
},
20+
"files": [
21+
"index.js",
22+
"index.d.ts",
23+
"build/math.js"
24+
]
25+
}

scripts/postbuild.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { readFileSync, writeFileSync } from "fs";
2+
3+
const base64String = readFileSync("build/math.wasm", "base64");
4+
5+
writeFileSync("build/math.js", `export const MathWasmBase64 = "${base64String}";`);

test/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { f64_pow } from "../index.js";
2+
import assert from "assert";
3+
4+
assert(f64_pow(2, 2) === 4, "2^2 == 4");
5+
assert(f64_pow(10, -5) === 0.00001, "2^2 == 4");

0 commit comments

Comments
 (0)