Skip to content

Commit

Permalink
upgrade to assembly script 0.25 and expose rounding types
Browse files Browse the repository at this point in the history
  • Loading branch information
ffortier committed Dec 6, 2022
1 parent 34634d3 commit 2baab52
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
26 changes: 24 additions & 2 deletions assembly/Big.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* All operations are immutable.
*/
export default class Big {
export default class Big {

/**
* {Big} instance with the value zero {0}.
Expand Down Expand Up @@ -69,6 +69,26 @@
*/
static RM: u8 = 1; // 0, 1, 2 or 3

/**
* Towards zero (i.e. truncate, no rounding).
*/
static readonly ROUND_DOWN: u8 = 0;

/**
* To nearest neighbour. If equidistant, round up.
*/
static readonly ROUND_HALF_UP: u8 = 1;

/**
* To nearest neighbour. If equidistant, to even.
*/
static readonly ROUND_HALF_EVEN: u8 = 2;

/**
* Away from zero.
*/
static readonly ROUND_UP: u8 = 3;

/**
* Default contructor.
* See {#of} for other options.
Expand Down Expand Up @@ -614,7 +634,7 @@
return yb;
}

let bl: i32, bt: i32, cmp: i32, ri: i32,
let bl: i32, cmp: i32, ri: i32,
bz = b.slice(),
ai = bl = b.length,
al = a.length,
Expand All @@ -634,6 +654,8 @@
// add zeros to make remainder as long as divisor
for (; rl++ < bl;) r.push(0);

cmp = 0;

let n: u8;
do {
// n is how many times the divisor goes into current remainder
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"asbuild": "npm run asbuild:debug && npm run asbuild:release"
},
"devDependencies": {
"assemblyscript": "^0.22.0"
"assemblyscript": "^0.25.0"
}
}

0 comments on commit 2baab52

Please sign in to comment.