@hazae41/fixed 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,10 +8,12 @@ export class Fixed {
8
8
  this.scale = 10n ** BigInt(shift);
9
9
  }
10
10
  toString() {
11
- const raw = this.value.toString().padStart(this.shift, "0");
11
+ const neg = this.value < 0n;
12
+ const val = neg ? -this.value : this.value;
13
+ const raw = val.toString().padStart(this.shift, "0");
12
14
  const head = raw.slice(0, raw.length - this.shift).replaceAll("0", " ").trimStart().replaceAll(" ", "0");
13
15
  const tail = raw.slice(raw.length - this.shift).replaceAll("0", " ").trimEnd().replaceAll(" ", "0");
14
- return (head || "0") + (tail && `.${tail}`);
16
+ return (neg ? "-" : "") + (head || "0") + (tail && `.${tail}`);
15
17
  }
16
18
  move(shift) {
17
19
  if (this.shift > shift)
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Fixed } from "./mod.js";
2
+ import { test } from "@hazae41/phobos";
3
+ test("fixed", () => {
4
+ console.log(new Fixed(123456789n, 18).toString());
5
+ console.log(new Fixed(-123456789n, 18).toString());
6
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/fixed",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "description": "Fixed-point numbers for the web",
6
6
  "homepage": "https://github.com/hazae41/fixed",
7
7
  "repository": "github:hazae41/fixed",