Skip to content

Commit

Permalink
Merge pull request #8 from ttulka/update_to_as_0_20
Browse files Browse the repository at this point in the history
Update to as 0.20.x
  • Loading branch information
ttulka authored Mar 30, 2022
2 parents 4d39250 + b98660f commit 3b482ce
Show file tree
Hide file tree
Showing 34 changed files with 324 additions and 399 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ npm install as-big
## Use

```typescript
import Big from "as-big/Big";
import Big from "as-big";

let r = Big.of(0.1) + Big.of(0.2); // Big(0.3)

Expand Down
14 changes: 6 additions & 8 deletions asconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"targets": {
"debug": {
"binaryFile": "build/untouched.wasm",
"textFile": "build/untouched.wat",
"outFile": "build/debug.wasm",
"textFile": "build/debug.wat",
"sourceMap": true,
"debug": true
},
"release": {
"binaryFile": "build/optimized.wasm",
"textFile": "build/optimized.wat",
"outFile": "build/release.wasm",
"textFile": "build/release.wat",
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 1,
"converge": true,
"noAssert": true
},
"test": {
"debug": true
}
},
"options": {
"exportRuntime": true
"exportRuntime": true,
"bindings": "esm"
}
}
69 changes: 60 additions & 9 deletions assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import Big from './Big';
export { Big };

// convinience functions for working from JS:

export function ofString(n: string): Big {
return Big.of(n);
}

export function ofNumber(n: number): Big {
return Big.of(n);
}
// convinience functions for working with Big within JS:

export function getDP(): i32 {
return Big.DP;
Expand All @@ -18,3 +10,62 @@ export function getDP(): i32 {
export function setDP(dp: i32): void {
Big.DP = dp;
}

export function abs(x: string): string {
return Big.of(x).abs().toString();
}

export function cmp(x: string, y: string): i8 {
return Big.of(x).cmp(y);
}

export function plus(x: string, y: string): string {
return Big.of(x).plus(y).toString();
}

export function minus(x: string, y: string): string {
return Big.of(x).minus(y).toString();
}

export function times(x: string, y: string): string {
return Big.of(x).times(y).toString();
}

export function div(x: string, y: string): string {
return Big.of(x).div(y).toString();
}

export function mod(x: string, y: string): string {
return Big.of(x).mod(y).toString();
}

export function pow(x: string, n: i32): string {
return Big.of(x).pow(n).toString();
}

export function round(x: string, dp: i32, rm: u8): string {
return Big.of(x).round(dp, rm).toString();
}

export function prec(x: string, sd: i32, rm: u8): string {
return Big.of(x).prec(sd, rm).toString();
}

export function sqrt(x: string): string {
return Big.of(x).sqrt().toString();
}

export function toExponential(x: string, dp: i32, rm: u8): string {
return Big.of(x).toExponential(dp, rm).toString();
}

export function toString(x: string): string {
return Big.of(x).toString();
}
export function ntoString(x: number): string {
return Big.of(x).toString();
}

export function toNumber(x: string): number {
return Big.of(x).toNumber();
}
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See contennt of [`assembly`](https://github.com/ttulka/as-big/tree/main/examples

```sh
npm i
npm run asbuild:optimized
npm run asbuild:release
```

## Test
Expand Down
13 changes: 8 additions & 5 deletions examples/asconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"targets": {
"debug": {
"binaryFile": "build/untouched.wasm",
"textFile": "build/untouched.wat",
"outFile": "build/debug.wasm",
"textFile": "build/debug.wat",
"sourceMap": true,
"debug": true
},
"release": {
"binaryFile": "build/optimized.wasm",
"textFile": "build/optimized.wat",
"outFile": "build/release.wasm",
"textFile": "build/release.wat",
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 1,
"converge": false,
"noAssert": false
}
},
"options": {}
"options": {
"exportRuntime": true,
"bindings": "esm"
}
}
2 changes: 1 addition & 1 deletion examples/assembly/basics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Big from 'as-big/Big';
import Big from 'as-big';

export function basics0(): number {

Expand Down
5 changes: 2 additions & 3 deletions examples/assembly/euler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Big from 'as-big/Big';
import Big from 'as-big/assembly/Big';

export function euler(n: i32 = 100, dp: i32 = 100): string {

Expand All @@ -18,8 +18,7 @@ export function euler(n: i32 = 100, dp: i32 = 100): string {
return sum.toString();
}

export function euler_native(n: i32 = 100): f64 {

export function euler_native(n: i32): f64 {
let sum = 0.0,
fac = 1.0;

Expand Down
2 changes: 1 addition & 1 deletion examples/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pi, pi_native } from './pi';
import { euler, euler_native } from './euler';
import { rump, rump_native } from './rumps-royal-pain';

export {
export {
basics0, basics1, basics2, basics3,
pi, pi_native,
euler, euler_native,
Expand Down
2 changes: 1 addition & 1 deletion examples/assembly/pi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Big from 'as-big/Big';
import Big from 'as-big/assembly/Big';

// Gregory-Leibniz series
// Pi = (4/1) - (4/3) + (4/5) - (4/7) + (4/9) - (4/11) + (4/13) - (4/15) ...
Expand Down
2 changes: 1 addition & 1 deletion examples/assembly/rumps-royal-pain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Big from 'as-big/Big';
import Big from 'as-big/assembly/Big';

// https://web.archive.org/web/20180729032331/http://arith22.gforge.inria.fr/slides/06-gustafson.pdf

Expand Down
32 changes: 17 additions & 15 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const fs = require("fs");
const loader = require("@assemblyscript/loader");
const wasm = loader.instantiateSync(fs.readFileSync(__dirname + "/build/optimized.wasm"), {});
module.exports = wasm.exports;
import {
basics0, basics1, basics2, basics3,
pi, pi_native,
euler, euler_native,
rump, rump_native
} from "./build/release.js";

const { __getString } = wasm.exports;
export { basics0, basics1, basics2, basics3 };

console.log('Basics #0:', wasm.exports.basics0());
console.log('Basics #1:', wasm.exports.basics1());
console.log('Basics #2:', __getString(wasm.exports.basics2()));
console.log('Basics #3:', wasm.exports.basics3());
console.log('Basics #0:', basics0());
console.log('Basics #1:', basics1());
console.log('Basics #2:', basics2());
console.log('Basics #3:', basics3());

console.log('Pi constant (native):', (wasm.exports.pi_native(10000)));
console.log('Pi constant (Big): ', __getString(wasm.exports.pi(10000, 100)));
console.log('Pi constant (native):', pi_native(10000));
console.log('Pi constant (Big): ', pi(10000, 100));

console.log('Euler’s constant (native):', wasm.exports.euler_native(100));
console.log('Euler’s constant (Big): ', __getString(wasm.exports.euler(100, 100)));
console.log('Euler’s constant (native):', euler_native(100));
console.log('Euler’s constant (Big): ', euler(100, 100));

console.log('Rump’s Royal Pain (native):', wasm.exports.rump_native());
console.log('Rump’s Royal Pain (Big): ', __getString(wasm.exports.rump()));
console.log('Rump’s Royal Pain (native):', rump_native());
console.log('Rump’s Royal Pain (Big): ', rump());
89 changes: 39 additions & 50 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3b482ce

Please sign in to comment.