@hazae41/fixed 1.0.1 → 2.0.0

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.
package/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ # MIT
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Fixed
2
2
 
3
- Fixed-point numbers in idiomatic TypeScript
3
+ Fixed-point numbers for the web
4
4
 
5
5
  ```bash
6
- npm i @hazae41/fixed
6
+ npm install @hazae41/fixed
7
7
  ```
8
8
 
9
- [**Node Package 📦**](https://www.npmjs.com/package/@hazae41/fixed)
9
+ [**📦 NPM**](https://www.npmjs.com/package/@hazae41/fixed)
10
10
 
11
11
  ## Features
12
12
 
@@ -17,10 +17,13 @@ npm i @hazae41/fixed
17
17
  ## Usage
18
18
 
19
19
  ```tsx
20
- const eth = new Fixed(123n, 0) // 123n
21
- const wei = fixed.move(18) // 123000000000000000000n
20
+ const x0 = new Fixed(123n, 0) // [123n;0]
21
+ const x18 = x0.move(18) // [123000000000000000000n;18]
22
22
 
23
- const wei2 = wei.add(new Fixed(1n, 18)) // 123000000000000000001n
23
+ const y18 = new Fixed(1n, 18) // [000000000000000000001n;18]
24
+ const z18 = x18.add(y18) // [123000000000000000001n;18]
24
25
 
25
- const str = wei2.toString() // "123.000000000000000001"
26
+ const str = z18.toString() // "123.000000000000000001"
27
+ const num = Number(str) // 123
28
+ const int = BigInt(num) // 123n
26
29
  ```
package/out/mod.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./mods/mod.ts";
package/out/mod.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./mods/mod.js";
@@ -0,0 +1,15 @@
1
+ export declare class Fixed {
2
+ readonly value: bigint;
3
+ readonly shift: number;
4
+ readonly scale: bigint;
5
+ constructor(value: bigint, shift: number);
6
+ toString(): string;
7
+ move(shift: number): Fixed;
8
+ add(other: Fixed): Fixed;
9
+ sub(other: Fixed): Fixed;
10
+ mul(other: Fixed): Fixed;
11
+ div(other: Fixed): Fixed;
12
+ floor(): Fixed;
13
+ ceil(): Fixed;
14
+ round(): Fixed;
15
+ }
@@ -0,0 +1,69 @@
1
+ export class Fixed {
2
+ value;
3
+ shift;
4
+ scale;
5
+ constructor(value, shift) {
6
+ this.value = value;
7
+ this.shift = shift;
8
+ this.scale = 10n ** BigInt(shift);
9
+ }
10
+ toString() {
11
+ const raw = this.value.toString().padStart(this.shift, "0");
12
+ const head = raw.slice(0, raw.length - this.shift).replaceAll("0", " ").trimStart().replaceAll(" ", "0");
13
+ const tail = raw.slice(raw.length - this.shift).replaceAll("0", " ").trimEnd().replaceAll(" ", "0");
14
+ return (head || "0") + (tail && `.${tail}`);
15
+ }
16
+ move(shift) {
17
+ if (this.shift > shift)
18
+ return new Fixed(this.value / (10n ** BigInt(this.shift - shift)), shift);
19
+ if (this.shift < shift)
20
+ return new Fixed(this.value * (10n ** BigInt(shift - this.shift)), shift);
21
+ return new Fixed(this.value, shift);
22
+ }
23
+ add(other) {
24
+ const dx = this.shift;
25
+ const dy = other.shift;
26
+ const dr = Math.max(dx, dy);
27
+ const tr = 10n ** BigInt(dr);
28
+ const tx = this.scale;
29
+ const ty = other.scale;
30
+ const vx = this.value;
31
+ const vy = other.value;
32
+ return new Fixed((vx * (tr / tx)) + (vy * (tr / ty)), dr);
33
+ }
34
+ sub(other) {
35
+ const dx = this.shift;
36
+ const dy = other.shift;
37
+ const dr = Math.max(dx, dy);
38
+ const tr = 10n ** BigInt(dr);
39
+ const tx = this.scale;
40
+ const ty = other.scale;
41
+ const vx = this.value;
42
+ const vy = other.value;
43
+ return new Fixed((vx * (tr / tx)) - (vy * (tr / ty)), dr);
44
+ }
45
+ mul(other) {
46
+ const dx = this.shift;
47
+ const dy = other.shift;
48
+ const dr = dx + dy;
49
+ const vx = this.value;
50
+ const vy = other.value;
51
+ return new Fixed(vx * vy, dr);
52
+ }
53
+ div(other) {
54
+ const dx = this.shift;
55
+ const ty = other.scale;
56
+ const vx = this.value;
57
+ const vy = other.value;
58
+ return new Fixed((vx * ty) / vy, dx);
59
+ }
60
+ floor() {
61
+ return new Fixed(this.value - (this.value % this.scale), this.shift);
62
+ }
63
+ ceil() {
64
+ return new Fixed(this.value + (this.scale - (this.value % this.scale)), this.shift);
65
+ }
66
+ round() {
67
+ return new Fixed(this.value + (this.scale / 2n) - ((this.value + (this.scale / 2n)) % this.scale), this.shift);
68
+ }
69
+ }
@@ -0,0 +1 @@
1
+ export * from "./fixed/mod.ts";
@@ -0,0 +1 @@
1
+ export * from "./fixed/mod.js";
package/package.json CHANGED
@@ -1,50 +1,35 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/fixed",
4
- "version": "1.0.1",
5
- "description": "Fixed-point numbers in idiomatic TypeScript",
4
+ "version": "2.0.0",
5
+ "description": "Fixed-point numbers for the web",
6
6
  "homepage": "https://github.com/hazae41/fixed",
7
7
  "repository": "github:hazae41/fixed",
8
8
  "author": "hazae41",
9
- "license": "MIT",
10
- "main": "./dist/cjs/index.cjs",
11
- "module": "./dist/esm/index.mjs",
12
- "types": "./dist/types/index.d.ts",
13
- "sideEffects": false,
14
- "files": [
15
- "./dist/esm",
16
- "./dist/cjs",
17
- "./dist/types"
18
- ],
19
9
  "scripts": {
20
- "build": "rimraf dist && rollup -c",
21
- "test": "node ./dist/test/index.test.mjs",
22
- "prepare": "npm run build"
23
- },
24
- "devDependencies": {
25
- "@hazae41/phobos": "^1.0.10",
26
- "@hazae41/rimraf": "^1.0.1",
27
- "@types/node": "^22.14.1",
28
- "@types/react": "^19.1.2",
29
- "rollup": "^4.40.0",
30
- "rollup-plugin-dts": "^6.2.1",
31
- "rollup-plugin-node-externals": "^8.0.0",
32
- "rollup-plugin-swc3": "^0.12.1"
10
+ "examine": "deno lint ./src && deno check ./src && deno test -RW ./src",
11
+ "prepack": "rm -rf ./out && tsc && tscousin"
33
12
  },
13
+ "files": [
14
+ "./out"
15
+ ],
34
16
  "exports": {
35
17
  ".": {
36
- "types": "./dist/types/index.d.ts",
37
- "import": "./dist/esm/index.mjs",
38
- "require": "./dist/cjs/index.cjs"
18
+ "types": "./out/mod.d.ts",
19
+ "import": "./out/mod.js"
39
20
  }
40
21
  },
22
+ "devDependencies": {
23
+ "@hazae41/phobos": "^2.0.16",
24
+ "@hazae41/tscousin": "^1.0.28",
25
+ "@types/node": "^25.9.2",
26
+ "deno": "^2.8.2",
27
+ "typescript": "^6.0.3"
28
+ },
41
29
  "keywords": [
42
30
  "typescript",
43
31
  "esmodules",
44
32
  "tested",
45
33
  "unit-tested"
46
- ],
47
- "dependencies": {
48
- "@hazae41/hex": "^1.0.1"
49
- }
34
+ ]
50
35
  }
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- var index = require('./mods/fixed/index.cjs');
4
-
5
-
6
-
7
- exports.BigIntFixedInit = index.BigIntFixedInit;
8
- exports.Fixed = index.Fixed;
9
- exports.ZeroHexFixedInit = index.ZeroHexFixedInit;
10
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- exports.BigInts = void 0;
4
- (function(BigInts) {
5
- function tensOf(value) {
6
- return 10n ** BigInt(value);
7
- }
8
- BigInts.tensOf = tensOf;
9
- })(exports.BigInts || (exports.BigInts = {}));
10
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../../src/libs/bigint/index.ts"],"sourcesContent":["\nexport namespace BigInts {\n\n export function tensOf(value: number) {\n return 10n ** BigInt(value)\n }\n\n}"],"names":["BigInts","tensOf","value","BigInt"],"mappings":";;;AACiBA,CAAAA,SAAAA,OAAAA,EAAAA;AAER,IAAA,SAASC,OAAOC,KAAa,EAAA;QAClC,OAAO,GAAG,IAAIC,MAAOD,CAAAA,KAAAA,CAAAA;AACvB;YAFgBD,MAAAA,GAAAA,MAAAA;AAIlB,CAAA,EANiBD,eAAAA,KAAAA,eAAAA,GAAAA,EAAAA,CAAAA,CAAAA;;"}
@@ -1,140 +0,0 @@
1
- 'use strict';
2
-
3
- var hex = require('@hazae41/hex');
4
- var index = require('../../libs/bigint/index.cjs');
5
-
6
- class ZeroHexFixedInit {
7
- value;
8
- decimals;
9
- constructor(value, decimals){
10
- this.value = value;
11
- this.decimals = decimals;
12
- }
13
- }
14
- class BigIntFixedInit {
15
- value;
16
- decimals;
17
- constructor(value, decimals){
18
- this.value = value;
19
- this.decimals = decimals;
20
- }
21
- }
22
- class Fixed {
23
- value;
24
- decimals;
25
- tens;
26
- constructor(value, decimals){
27
- this.value = value;
28
- this.decimals = decimals;
29
- this.tens = index.BigInts.tensOf(decimals);
30
- }
31
- static unit(decimals) {
32
- return new Fixed(index.BigInts.tensOf(decimals), decimals);
33
- }
34
- static from(from) {
35
- if (from instanceof Fixed) return from;
36
- if (typeof from.value === "bigint") return new Fixed(from.value, from.decimals);
37
- return new Fixed(hex.ZeroHexString.toBigInt(from.value), from.decimals);
38
- }
39
- static fromBigInt(value) {
40
- return new Fixed(value, 0);
41
- }
42
- static fromBigIntInit(init) {
43
- return new Fixed(init.value, init.decimals);
44
- }
45
- static fromZeroHexInit(init) {
46
- return new Fixed(hex.ZeroHexString.toBigInt(init.value), init.decimals);
47
- }
48
- static fromZeroHexString(value) {
49
- return new Fixed(hex.ZeroHexString.toBigInt(value), 0);
50
- }
51
- static fromDecimalString(text) {
52
- const [whole = "0", decimal = "0"] = text.split(".");
53
- const value = BigInt(whole + decimal);
54
- return new Fixed(value, decimal.length);
55
- }
56
- toBigInt() {
57
- return this.value;
58
- }
59
- toZeroHexString() {
60
- return hex.ZeroHexString.fromBigInt(this.value);
61
- }
62
- toBigIntInit() {
63
- return new BigIntFixedInit(this.value, this.decimals);
64
- }
65
- toZeroHexInit() {
66
- return new ZeroHexFixedInit(hex.ZeroHexString.fromBigInt(this.value), this.decimals);
67
- }
68
- toDecimalString() {
69
- const raw = this.value.toString().padStart(this.decimals, "0");
70
- const whole = raw.slice(0, raw.length - this.decimals).replaceAll("0", " ").trimStart().replaceAll(" ", "0");
71
- const decimal = raw.slice(raw.length - this.decimals).replaceAll("0", " ").trimEnd().replaceAll(" ", "0");
72
- if (!decimal) return whole || "0";
73
- return `${whole || "0"}.${decimal}`;
74
- }
75
- toString() {
76
- return this.toDecimalString();
77
- }
78
- toJSON() {
79
- return this.toZeroHexInit();
80
- }
81
- as(decimals) {
82
- return new Fixed(this.value, decimals);
83
- }
84
- move(decimals) {
85
- if (this.decimals > decimals) return new Fixed(this.value / index.BigInts.tensOf(this.decimals - decimals), decimals);
86
- if (this.decimals < decimals) return new Fixed(this.value * index.BigInts.tensOf(decimals - this.decimals), decimals);
87
- return new Fixed(this.value, decimals);
88
- }
89
- add(other) {
90
- const dx = this.decimals;
91
- const dy = other.decimals;
92
- const dr = Math.max(dx, dy);
93
- const tr = index.BigInts.tensOf(dr);
94
- const tx = this.tens;
95
- const ty = other.tens;
96
- const vx = this.value;
97
- const vy = other.value;
98
- return new Fixed(vx * (tr / tx) + vy * (tr / ty), dr);
99
- }
100
- sub(other) {
101
- const dx = this.decimals;
102
- const dy = other.decimals;
103
- const dr = Math.max(dx, dy);
104
- const tr = index.BigInts.tensOf(dr);
105
- const tx = this.tens;
106
- const ty = other.tens;
107
- const vx = this.value;
108
- const vy = other.value;
109
- return new Fixed(vx * (tr / tx) - vy * (tr / ty), dr);
110
- }
111
- mul(other) {
112
- const dx = this.decimals;
113
- const dy = other.decimals;
114
- const dr = dx + dy;
115
- const vx = this.value;
116
- const vy = other.value;
117
- return new Fixed(vx * vy, dr);
118
- }
119
- div(other) {
120
- const dx = this.decimals;
121
- const ty = other.tens;
122
- const vx = this.value;
123
- const vy = other.value;
124
- return new Fixed(vx * ty / vy, dx);
125
- }
126
- floor() {
127
- return new Fixed(this.value - this.value % this.tens, this.decimals);
128
- }
129
- ceil() {
130
- return new Fixed(this.value + (this.tens - this.value % this.tens), this.decimals);
131
- }
132
- round() {
133
- return new Fixed(this.value + this.tens / 2n - (this.value + this.tens / 2n) % this.tens, this.decimals);
134
- }
135
- }
136
-
137
- exports.BigIntFixedInit = BigIntFixedInit;
138
- exports.Fixed = Fixed;
139
- exports.ZeroHexFixedInit = ZeroHexFixedInit;
140
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../../src/mods/fixed/index.ts"],"sourcesContent":["import { ZeroHexString } from \"@hazae41/hex\"\nimport { BigInts } from \"libs/bigint/index.js\"\n\nexport type FixedInit<D extends number = number> =\n | ZeroHexFixedInit<D>\n | BigIntFixedInit<D>\n\nexport interface ZeroHexFixedInit<D extends number = number> {\n readonly value: ZeroHexString,\n readonly decimals: D\n}\n\nexport class ZeroHexFixedInit<D extends number = number> {\n\n constructor(\n readonly value: ZeroHexString,\n readonly decimals: D\n ) { }\n\n}\n\nexport interface BigIntFixedInit<D extends number = number> {\n readonly value: bigint,\n readonly decimals: D\n}\n\nexport class BigIntFixedInit<D extends number = number> {\n\n constructor(\n readonly value: bigint,\n readonly decimals: D\n ) { }\n\n}\n\nexport namespace Fixed {\n\n export type From<D extends number = number> =\n | BigIntFixedInit<D>\n | ZeroHexFixedInit<D>\n\n}\n\nexport class Fixed<D extends number = number> implements BigIntFixedInit {\n\n readonly tens: bigint\n\n constructor(\n readonly value: bigint,\n readonly decimals: D\n ) {\n this.tens = BigInts.tensOf(decimals)\n }\n\n static unit<D extends number = number>(decimals: D) {\n return new Fixed(BigInts.tensOf(decimals), decimals)\n }\n\n static from<D extends number = number>(from: Fixed.From<D>) {\n if (from instanceof Fixed)\n return from\n if (typeof from.value === \"bigint\")\n return new Fixed(from.value, from.decimals)\n return new Fixed(ZeroHexString.toBigInt(from.value), from.decimals)\n }\n\n static fromBigInt(value: bigint) {\n return new Fixed(value, 0)\n }\n\n static fromBigIntInit<D extends number>(init: BigIntFixedInit<D>) {\n return new Fixed(init.value, init.decimals)\n }\n\n static fromZeroHexInit<D extends number>(init: ZeroHexFixedInit<D>) {\n return new Fixed(ZeroHexString.toBigInt(init.value), init.decimals)\n }\n\n static fromZeroHexString(value: ZeroHexString) {\n return new Fixed(ZeroHexString.toBigInt(value), 0)\n }\n\n static fromDecimalString(text: string) {\n const [whole = \"0\", decimal = \"0\"] = text.split(\".\")\n\n const value = BigInt(whole + decimal)\n\n return new Fixed(value, decimal.length)\n }\n\n toBigInt() {\n return this.value\n }\n\n toZeroHexString() {\n return ZeroHexString.fromBigInt(this.value)\n }\n\n toBigIntInit() {\n return new BigIntFixedInit(this.value, this.decimals)\n }\n\n toZeroHexInit() {\n return new ZeroHexFixedInit(ZeroHexString.fromBigInt(this.value), this.decimals)\n }\n\n toDecimalString() {\n const raw = this.value.toString().padStart(this.decimals, \"0\")\n\n const whole = raw.slice(0, raw.length - this.decimals).replaceAll(\"0\", \" \").trimStart().replaceAll(\" \", \"0\")\n const decimal = raw.slice(raw.length - this.decimals).replaceAll(\"0\", \" \").trimEnd().replaceAll(\" \", \"0\")\n\n if (!decimal)\n return (whole || \"0\")\n\n return `${whole || \"0\"}.${decimal}`\n }\n\n toString() {\n return this.toDecimalString()\n }\n\n toJSON() {\n return this.toZeroHexInit()\n }\n\n as(decimals: number) {\n return new Fixed(this.value, decimals)\n }\n\n move<D extends number>(decimals: D): Fixed<D> {\n if (this.decimals > decimals)\n return new Fixed(this.value / BigInts.tensOf(this.decimals - decimals), decimals)\n if (this.decimals < decimals)\n return new Fixed(this.value * BigInts.tensOf(decimals - this.decimals), decimals)\n return new Fixed(this.value, decimals)\n }\n\n add(other: Fixed) {\n const dx = this.decimals\n const dy = other.decimals\n\n const dr = Math.max(dx, dy)\n const tr = BigInts.tensOf(dr)\n\n const tx = this.tens\n const ty = other.tens\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed((vx * (tr / tx)) + (vy * (tr / ty)), dr)\n }\n\n sub(other: Fixed) {\n const dx = this.decimals\n const dy = other.decimals\n\n const dr = Math.max(dx, dy)\n const tr = BigInts.tensOf(dr)\n\n const tx = this.tens\n const ty = other.tens\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed((vx * (tr / tx)) - (vy * (tr / ty)), dr)\n }\n\n mul(other: Fixed) {\n const dx = this.decimals\n const dy = other.decimals\n\n const dr = dx + dy\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed(vx * vy, dr)\n }\n\n div(other: Fixed) {\n const dx = this.decimals\n const ty = other.tens\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed((vx * ty) / vy, dx)\n }\n\n floor() {\n return new Fixed(this.value - (this.value % this.tens), this.decimals)\n }\n\n ceil() {\n return new Fixed(this.value + (this.tens - (this.value % this.tens)), this.decimals)\n }\n\n round() {\n return new Fixed(this.value + (this.tens / 2n) - ((this.value + (this.tens / 2n)) % this.tens), this.decimals)\n }\n\n}\n"],"names":["ZeroHexFixedInit","constructor","decimals","value","BigIntFixedInit","Fixed","tens","BigInts","tensOf","unit","from","ZeroHexString","toBigInt","fromBigInt","fromBigIntInit","init","fromZeroHexInit","fromZeroHexString","fromDecimalString","text","whole","decimal","split","BigInt","length","toZeroHexString","toBigIntInit","toZeroHexInit","toDecimalString","raw","toString","padStart","slice","replaceAll","trimStart","trimEnd","toJSON","as","move","add","other","dx","dy","dr","Math","max","tr","tx","ty","vx","vy","sub","mul","div","floor","ceil","round"],"mappings":";;;;;AAYO,MAAMA,gBAAAA,CAAAA;;;AAEXC,IAAAA,WAAAA,CACE,KAA6B,EACpBC,QAAW,CACpB;aAFSC,KAAAA,GAAAA,KAAAA;aACAD,QAAAA,GAAAA,QAAAA;AACP;AAEN;AAOO,MAAME,eAAAA,CAAAA;;;AAEXH,IAAAA,WAAAA,CACE,KAAsB,EACbC,QAAW,CACpB;aAFSC,KAAAA,GAAAA,KAAAA;aACAD,QAAAA,GAAAA,QAAAA;AACP;AAEN;AAUO,MAAMG,KAAAA,CAAAA;;;IAEFC,IAAY;AAErBL,IAAAA,WAAAA,CACE,KAAsB,EACbC,QAAW,CACpB;aAFSC,KAAAA,GAAAA,KAAAA;aACAD,QAAAA,GAAAA,QAAAA;AAET,QAAA,IAAI,CAACI,IAAI,GAAGC,aAAAA,CAAQC,MAAM,CAACN,QAAAA,CAAAA;AAC7B;IAEA,OAAOO,IAAAA,CAAgCP,QAAW,EAAE;AAClD,QAAA,OAAO,IAAIG,KAAAA,CAAME,aAAQC,CAAAA,MAAM,CAACN,QAAWA,CAAAA,EAAAA,QAAAA,CAAAA;AAC7C;IAEA,OAAOQ,IAAAA,CAAgCA,IAAmB,EAAE;QAC1D,IAAIA,IAAAA,YAAgBL,OAClB,OAAOK,IAAAA;AACT,QAAA,IAAI,OAAOA,IAAAA,CAAKP,KAAK,KAAK,QACxB,EAAA,OAAO,IAAIE,KAAAA,CAAMK,IAAKP,CAAAA,KAAK,EAAEO,IAAAA,CAAKR,QAAQ,CAAA;QAC5C,OAAO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AK,GAAG,IAAI,CAACG,IAAI,EAAG,IAAI,CAACJ,QAAQ,CAAA;AACvE;IAEAqD,IAAO,GAAA;QACL,OAAO,IAAIlD,MAAM,IAAI,CAACF,KAAK,IAAI,IAAI,CAACG,IAAI,GAAI,IAAI,CAACH,KAAK,GAAG,IAAI,CAACG,IAAI,CAAA,EAAI,IAAI,CAACJ,QAAQ,CAAA;AACrF;IAEAsD,KAAQ,GAAA;AACN,QAAA,OAAO,IAAInD,KAAAA,CAAM,IAAI,CAACF,KAAK,GAAI,IAAI,CAACG,IAAI,GAAG,EAAE,GAAK,CAAC,IAAI,CAACH,KAAK,GAAI,IAAI,CAACG,IAAI,GAAG,EAAE,IAAK,IAAI,CAACA,IAAI,EAAG,IAAI,CAACJ,QAAQ,CAAA;AAC/G;AAEF;;;;;;"}
@@ -1,2 +0,0 @@
1
- export { BigIntFixedInit, Fixed, ZeroHexFixedInit } from './mods/fixed/index.mjs';
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- var BigInts;
2
- (function(BigInts) {
3
- function tensOf(value) {
4
- return 10n ** BigInt(value);
5
- }
6
- BigInts.tensOf = tensOf;
7
- })(BigInts || (BigInts = {}));
8
-
9
- export { BigInts };
10
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/libs/bigint/index.ts"],"sourcesContent":["\nexport namespace BigInts {\n\n export function tensOf(value: number) {\n return 10n ** BigInt(value)\n }\n\n}"],"names":["BigInts","tensOf","value","BigInt"],"mappings":";AACiBA,CAAAA,SAAAA,OAAAA,EAAAA;AAER,IAAA,SAASC,OAAOC,KAAa,EAAA;QAClC,OAAO,GAAG,IAAIC,MAAOD,CAAAA,KAAAA,CAAAA;AACvB;YAFgBD,MAAAA,GAAAA,MAAAA;AAIlB,CAAA,EANiBD,OAAAA,KAAAA,OAAAA,GAAAA,EAAAA,CAAAA,CAAAA;;;;"}
@@ -1,136 +0,0 @@
1
- import { ZeroHexString } from '@hazae41/hex';
2
- import { BigInts } from '../../libs/bigint/index.mjs';
3
-
4
- class ZeroHexFixedInit {
5
- value;
6
- decimals;
7
- constructor(value, decimals){
8
- this.value = value;
9
- this.decimals = decimals;
10
- }
11
- }
12
- class BigIntFixedInit {
13
- value;
14
- decimals;
15
- constructor(value, decimals){
16
- this.value = value;
17
- this.decimals = decimals;
18
- }
19
- }
20
- class Fixed {
21
- value;
22
- decimals;
23
- tens;
24
- constructor(value, decimals){
25
- this.value = value;
26
- this.decimals = decimals;
27
- this.tens = BigInts.tensOf(decimals);
28
- }
29
- static unit(decimals) {
30
- return new Fixed(BigInts.tensOf(decimals), decimals);
31
- }
32
- static from(from) {
33
- if (from instanceof Fixed) return from;
34
- if (typeof from.value === "bigint") return new Fixed(from.value, from.decimals);
35
- return new Fixed(ZeroHexString.toBigInt(from.value), from.decimals);
36
- }
37
- static fromBigInt(value) {
38
- return new Fixed(value, 0);
39
- }
40
- static fromBigIntInit(init) {
41
- return new Fixed(init.value, init.decimals);
42
- }
43
- static fromZeroHexInit(init) {
44
- return new Fixed(ZeroHexString.toBigInt(init.value), init.decimals);
45
- }
46
- static fromZeroHexString(value) {
47
- return new Fixed(ZeroHexString.toBigInt(value), 0);
48
- }
49
- static fromDecimalString(text) {
50
- const [whole = "0", decimal = "0"] = text.split(".");
51
- const value = BigInt(whole + decimal);
52
- return new Fixed(value, decimal.length);
53
- }
54
- toBigInt() {
55
- return this.value;
56
- }
57
- toZeroHexString() {
58
- return ZeroHexString.fromBigInt(this.value);
59
- }
60
- toBigIntInit() {
61
- return new BigIntFixedInit(this.value, this.decimals);
62
- }
63
- toZeroHexInit() {
64
- return new ZeroHexFixedInit(ZeroHexString.fromBigInt(this.value), this.decimals);
65
- }
66
- toDecimalString() {
67
- const raw = this.value.toString().padStart(this.decimals, "0");
68
- const whole = raw.slice(0, raw.length - this.decimals).replaceAll("0", " ").trimStart().replaceAll(" ", "0");
69
- const decimal = raw.slice(raw.length - this.decimals).replaceAll("0", " ").trimEnd().replaceAll(" ", "0");
70
- if (!decimal) return whole || "0";
71
- return `${whole || "0"}.${decimal}`;
72
- }
73
- toString() {
74
- return this.toDecimalString();
75
- }
76
- toJSON() {
77
- return this.toZeroHexInit();
78
- }
79
- as(decimals) {
80
- return new Fixed(this.value, decimals);
81
- }
82
- move(decimals) {
83
- if (this.decimals > decimals) return new Fixed(this.value / BigInts.tensOf(this.decimals - decimals), decimals);
84
- if (this.decimals < decimals) return new Fixed(this.value * BigInts.tensOf(decimals - this.decimals), decimals);
85
- return new Fixed(this.value, decimals);
86
- }
87
- add(other) {
88
- const dx = this.decimals;
89
- const dy = other.decimals;
90
- const dr = Math.max(dx, dy);
91
- const tr = BigInts.tensOf(dr);
92
- const tx = this.tens;
93
- const ty = other.tens;
94
- const vx = this.value;
95
- const vy = other.value;
96
- return new Fixed(vx * (tr / tx) + vy * (tr / ty), dr);
97
- }
98
- sub(other) {
99
- const dx = this.decimals;
100
- const dy = other.decimals;
101
- const dr = Math.max(dx, dy);
102
- const tr = BigInts.tensOf(dr);
103
- const tx = this.tens;
104
- const ty = other.tens;
105
- const vx = this.value;
106
- const vy = other.value;
107
- return new Fixed(vx * (tr / tx) - vy * (tr / ty), dr);
108
- }
109
- mul(other) {
110
- const dx = this.decimals;
111
- const dy = other.decimals;
112
- const dr = dx + dy;
113
- const vx = this.value;
114
- const vy = other.value;
115
- return new Fixed(vx * vy, dr);
116
- }
117
- div(other) {
118
- const dx = this.decimals;
119
- const ty = other.tens;
120
- const vx = this.value;
121
- const vy = other.value;
122
- return new Fixed(vx * ty / vy, dx);
123
- }
124
- floor() {
125
- return new Fixed(this.value - this.value % this.tens, this.decimals);
126
- }
127
- ceil() {
128
- return new Fixed(this.value + (this.tens - this.value % this.tens), this.decimals);
129
- }
130
- round() {
131
- return new Fixed(this.value + this.tens / 2n - (this.value + this.tens / 2n) % this.tens, this.decimals);
132
- }
133
- }
134
-
135
- export { BigIntFixedInit, Fixed, ZeroHexFixedInit };
136
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/mods/fixed/index.ts"],"sourcesContent":["import { ZeroHexString } from \"@hazae41/hex\"\nimport { BigInts } from \"libs/bigint/index.js\"\n\nexport type FixedInit<D extends number = number> =\n | ZeroHexFixedInit<D>\n | BigIntFixedInit<D>\n\nexport interface ZeroHexFixedInit<D extends number = number> {\n readonly value: ZeroHexString,\n readonly decimals: D\n}\n\nexport class ZeroHexFixedInit<D extends number = number> {\n\n constructor(\n readonly value: ZeroHexString,\n readonly decimals: D\n ) { }\n\n}\n\nexport interface BigIntFixedInit<D extends number = number> {\n readonly value: bigint,\n readonly decimals: D\n}\n\nexport class BigIntFixedInit<D extends number = number> {\n\n constructor(\n readonly value: bigint,\n readonly decimals: D\n ) { }\n\n}\n\nexport namespace Fixed {\n\n export type From<D extends number = number> =\n | BigIntFixedInit<D>\n | ZeroHexFixedInit<D>\n\n}\n\nexport class Fixed<D extends number = number> implements BigIntFixedInit {\n\n readonly tens: bigint\n\n constructor(\n readonly value: bigint,\n readonly decimals: D\n ) {\n this.tens = BigInts.tensOf(decimals)\n }\n\n static unit<D extends number = number>(decimals: D) {\n return new Fixed(BigInts.tensOf(decimals), decimals)\n }\n\n static from<D extends number = number>(from: Fixed.From<D>) {\n if (from instanceof Fixed)\n return from\n if (typeof from.value === \"bigint\")\n return new Fixed(from.value, from.decimals)\n return new Fixed(ZeroHexString.toBigInt(from.value), from.decimals)\n }\n\n static fromBigInt(value: bigint) {\n return new Fixed(value, 0)\n }\n\n static fromBigIntInit<D extends number>(init: BigIntFixedInit<D>) {\n return new Fixed(init.value, init.decimals)\n }\n\n static fromZeroHexInit<D extends number>(init: ZeroHexFixedInit<D>) {\n return new Fixed(ZeroHexString.toBigInt(init.value), init.decimals)\n }\n\n static fromZeroHexString(value: ZeroHexString) {\n return new Fixed(ZeroHexString.toBigInt(value), 0)\n }\n\n static fromDecimalString(text: string) {\n const [whole = \"0\", decimal = \"0\"] = text.split(\".\")\n\n const value = BigInt(whole + decimal)\n\n return new Fixed(value, decimal.length)\n }\n\n toBigInt() {\n return this.value\n }\n\n toZeroHexString() {\n return ZeroHexString.fromBigInt(this.value)\n }\n\n toBigIntInit() {\n return new BigIntFixedInit(this.value, this.decimals)\n }\n\n toZeroHexInit() {\n return new ZeroHexFixedInit(ZeroHexString.fromBigInt(this.value), this.decimals)\n }\n\n toDecimalString() {\n const raw = this.value.toString().padStart(this.decimals, \"0\")\n\n const whole = raw.slice(0, raw.length - this.decimals).replaceAll(\"0\", \" \").trimStart().replaceAll(\" \", \"0\")\n const decimal = raw.slice(raw.length - this.decimals).replaceAll(\"0\", \" \").trimEnd().replaceAll(\" \", \"0\")\n\n if (!decimal)\n return (whole || \"0\")\n\n return `${whole || \"0\"}.${decimal}`\n }\n\n toString() {\n return this.toDecimalString()\n }\n\n toJSON() {\n return this.toZeroHexInit()\n }\n\n as(decimals: number) {\n return new Fixed(this.value, decimals)\n }\n\n move<D extends number>(decimals: D): Fixed<D> {\n if (this.decimals > decimals)\n return new Fixed(this.value / BigInts.tensOf(this.decimals - decimals), decimals)\n if (this.decimals < decimals)\n return new Fixed(this.value * BigInts.tensOf(decimals - this.decimals), decimals)\n return new Fixed(this.value, decimals)\n }\n\n add(other: Fixed) {\n const dx = this.decimals\n const dy = other.decimals\n\n const dr = Math.max(dx, dy)\n const tr = BigInts.tensOf(dr)\n\n const tx = this.tens\n const ty = other.tens\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed((vx * (tr / tx)) + (vy * (tr / ty)), dr)\n }\n\n sub(other: Fixed) {\n const dx = this.decimals\n const dy = other.decimals\n\n const dr = Math.max(dx, dy)\n const tr = BigInts.tensOf(dr)\n\n const tx = this.tens\n const ty = other.tens\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed((vx * (tr / tx)) - (vy * (tr / ty)), dr)\n }\n\n mul(other: Fixed) {\n const dx = this.decimals\n const dy = other.decimals\n\n const dr = dx + dy\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed(vx * vy, dr)\n }\n\n div(other: Fixed) {\n const dx = this.decimals\n const ty = other.tens\n\n const vx = this.value\n const vy = other.value\n\n return new Fixed((vx * ty) / vy, dx)\n }\n\n floor() {\n return new Fixed(this.value - (this.value % this.tens), this.decimals)\n }\n\n ceil() {\n return new Fixed(this.value + (this.tens - (this.value % this.tens)), this.decimals)\n }\n\n round() {\n return new Fixed(this.value + (this.tens / 2n) - ((this.value + (this.tens / 2n)) % this.tens), this.decimals)\n }\n\n}\n"],"names":["ZeroHexFixedInit","constructor","decimals","value","BigIntFixedInit","Fixed","tens","BigInts","tensOf","unit","from","ZeroHexString","toBigInt","fromBigInt","fromBigIntInit","init","fromZeroHexInit","fromZeroHexString","fromDecimalString","text","whole","decimal","split","BigInt","length","toZeroHexString","toBigIntInit","toZeroHexInit","toDecimalString","raw","toString","padStart","slice","replaceAll","trimStart","trimEnd","toJSON","as","move","add","other","dx","dy","dr","Math","max","tr","tx","ty","vx","vy","sub","mul","div","floor","ceil","round"],"mappings":";;;AAYO,MAAMA,gBAAAA,CAAAA;;;AAEXC,IAAAA,WAAAA,CACE,KAA6B,EACpBC,QAAW,CACpB;aAFSC,KAAAA,GAAAA,KAAAA;aACAD,QAAAA,GAAAA,QAAAA;AACP;AAEN;AAOO,MAAME,eAAAA,CAAAA;;;AAEXH,IAAAA,WAAAA,CACE,KAAsB,EACbC,QAAW,CACpB;aAFSC,KAAAA,GAAAA,KAAAA;aACAD,QAAAA,GAAAA,QAAAA;AACP;AAEN;AAUO,MAAMG,KAAAA,CAAAA;;;IAEFC,IAAY;AAErBL,IAAAA,WAAAA,CACE,KAAsB,EACbC,QAAW,CACpB;aAFSC,KAAAA,GAAAA,KAAAA;aACAD,QAAAA,GAAAA,QAAAA;AAET,QAAA,IAAI,CAACI,IAAI,GAAGC,OAAAA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EAAAA,CAAAA;AAC5B;AAEAU,IAAAA,GAAAA,CAAIb,KAAY,EAAE;QAChB,MAAMC,EAAAA,GAAK,IAAI,CAACvC,QAAQ;QACxB,MAAM8C,EAAAA,GAAKR,MAAMlC,IAAI;QAErB,MAAM2C,EAAAA,GAAK,IAAI,CAAC9C,KAAK;QACrB,MAAM+C,EAAAA,GAAKV,MAAMrC,KAAK;AAEtB,QAAA,OAAO,IAAIE,KAAAA,CAAM,EAAC4C,GAAKD,KAAME,EAAIT,EAAAA,EAAAA,CAAAA;AACnC;IAEAa,KAAQ,GAAA;AACN,QAAA,OAAO,IAAIjD,KAAM,CAAA,IAAI,CAACF,KAAK,GAAI,IAAI,CAACA,KAAK,GAAG,IAAI,CAACG,IAAI,EAAG,IAAI,CAACJ,QAAQ,CAAA;AACvE;IAEAqD,IAAO,GAAA;QACL,OAAO,IAAIlD,MAAM,IAAI,CAACF,KAAK,IAAI,IAAI,CAACG,IAAI,GAAI,IAAI,CAACH,KAAK,GAAG,IAAI,CAACG,IAAI,CAAA,EAAI,IAAI,CAACJ,QAAQ,CAAA;AACrF;IAEAsD,KAAQ,GAAA;AACN,QAAA,OAAO,IAAInD,KAAAA,CAAM,IAAI,CAACF,KAAK,GAAI,IAAI,CAACG,IAAI,GAAG,EAAE,GAAK,CAAC,IAAI,CAACH,KAAK,GAAI,IAAI,CAACG,IAAI,GAAG,EAAE,IAAK,IAAI,CAACA,IAAI,EAAG,IAAI,CAACJ,QAAQ,CAAA;AAC/G;AAEF;;;;"}
@@ -1 +0,0 @@
1
- export { BigIntFixedInit, Fixed, FixedInit, ZeroHexFixedInit } from './mods/fixed/index.js';
@@ -1,58 +0,0 @@
1
- import { ZeroHexString } from '@hazae41/hex';
2
-
3
- type FixedInit<D extends number = number> = ZeroHexFixedInit<D> | BigIntFixedInit<D>;
4
- interface ZeroHexFixedInit<D extends number = number> {
5
- readonly value: ZeroHexString;
6
- readonly decimals: D;
7
- }
8
- declare class ZeroHexFixedInit<D extends number = number> {
9
- readonly value: ZeroHexString;
10
- readonly decimals: D;
11
- constructor(value: ZeroHexString, decimals: D);
12
- }
13
- interface BigIntFixedInit<D extends number = number> {
14
- readonly value: bigint;
15
- readonly decimals: D;
16
- }
17
- declare class BigIntFixedInit<D extends number = number> {
18
- readonly value: bigint;
19
- readonly decimals: D;
20
- constructor(value: bigint, decimals: D);
21
- }
22
- declare namespace Fixed {
23
- type From<D extends number = number> = BigIntFixedInit<D> | ZeroHexFixedInit<D>;
24
- }
25
- declare class Fixed<D extends number = number> implements BigIntFixedInit {
26
- readonly value: bigint;
27
- readonly decimals: D;
28
- readonly tens: bigint;
29
- constructor(value: bigint, decimals: D);
30
- static unit<D extends number = number>(decimals: D): Fixed<D>;
31
- static from<D extends number = number>(from: Fixed.From<D>): Fixed<any>;
32
- static fromBigInt(value: bigint): Fixed<0>;
33
- static fromBigIntInit<D extends number>(init: BigIntFixedInit<D>): Fixed<D>;
34
- static fromZeroHexInit<D extends number>(init: ZeroHexFixedInit<D>): Fixed<D>;
35
- static fromZeroHexString(value: ZeroHexString): Fixed<0>;
36
- static fromDecimalString(text: string): Fixed<number>;
37
- toBigInt(): bigint;
38
- toZeroHexString(): `0x${string}` & {
39
- readonly [Symbol.isZeroHex]: true;
40
- };
41
- toBigIntInit(): BigIntFixedInit<D>;
42
- toZeroHexInit(): ZeroHexFixedInit<D>;
43
- toDecimalString(): string;
44
- toString(): string;
45
- toJSON(): ZeroHexFixedInit<D>;
46
- as(decimals: number): Fixed<number>;
47
- move<D extends number>(decimals: D): Fixed<D>;
48
- add(other: Fixed): Fixed<number>;
49
- sub(other: Fixed): Fixed<number>;
50
- mul(other: Fixed): Fixed<number>;
51
- div(other: Fixed): Fixed<D>;
52
- floor(): Fixed<D>;
53
- ceil(): Fixed<D>;
54
- round(): Fixed<D>;
55
- }
56
-
57
- export { BigIntFixedInit, Fixed, ZeroHexFixedInit };
58
- export type { FixedInit };