@kikuchan/decimal 0.1.0-alpha.2 → 0.1.0-alpha.3

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/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "arbitrary",
7
7
  "bigint"
8
8
  ],
9
- "version": "0.1.0-alpha.2",
9
+ "version": "0.1.0-alpha.3",
10
10
  "type": "module",
11
11
  "main": "./src/index.ts",
12
12
  "author": "kikuchan <kikuchan98@gmail.com>",
package/src/index.ts CHANGED
@@ -407,7 +407,11 @@ class DecimalImpl implements Decimal {
407
407
  }
408
408
 
409
409
  #stripTrailingZeros$(): this {
410
- if (this.digits <= 0n || this.coeff === 0n) return this;
410
+ if (this.coeff === 0n) {
411
+ this.digits = 0n;
412
+ return this;
413
+ }
414
+ if (this.digits <= 0n) return this;
411
415
  while (this.digits > 0n && this.coeff % 10n === 0n) {
412
416
  this.coeff /= 10n;
413
417
  this.digits -= 1n;
@@ -1186,11 +1186,18 @@ describe('Decimal boundaries', () => {
1186
1186
  expect(clamped.eq(original)).toBe(true);
1187
1187
  });
1188
1188
 
1189
- it('rescale preserves explicit zero scales without stripping digits', () => {
1189
+ it('compresses zero to standard form with rescale', () => {
1190
1190
  const value = Decimal({ coeff: 0n, digits: 5n });
1191
1191
  const compressed = value.rescale();
1192
- expect(compressed.digits).toBe(5n);
1193
- expect(compressed.toString()).toBe('0.00000');
1192
+ expect(compressed.digits).toBe(0n);
1193
+ expect(compressed.toString()).toBe('0');
1194
+ });
1195
+
1196
+ it('compresses zero with negative exponent to standard form with rescale', () => {
1197
+ const value = Decimal({ coeff: 0n, digits: -5n });
1198
+ const compressed = value.rescale();
1199
+ expect(compressed.digits).toBe(0n);
1200
+ expect(compressed.toString()).toBe('0');
1194
1201
  });
1195
1202
  });
1196
1203