@xylabs/decimal-precision 5.0.34 → 5.0.35

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/decimal-precision",
3
- "version": "5.0.34",
3
+ "version": "5.0.35",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "decimal",
@@ -40,7 +40,10 @@
40
40
  "types": "./dist/neutral/index.d.ts",
41
41
  "files": [
42
42
  "dist",
43
- "src"
43
+ "src",
44
+ "!**/*.bench.*",
45
+ "!**/*.spec.*",
46
+ "!**/*.test.*"
44
47
  ],
45
48
  "devDependencies": {
46
49
  "@xylabs/ts-scripts-yarn3": "~7.2.8",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=fromFixedPoint.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fromFixedPoint.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/fromFixedPoint.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=toDecimalPrecision.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toDecimalPrecision.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/toDecimalPrecision.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=toFixedPoint.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toFixedPoint.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/toFixedPoint.spec.ts"],"names":[],"mappings":""}
@@ -1,35 +0,0 @@
1
- import {
2
- describe, expect, it,
3
- } from 'vitest'
4
-
5
- import { fromFixedPoint } from '../fromFixedPoint.ts'
6
-
7
- describe('fromFixedPoint', () => {
8
- it('should convert a fixed-point bigint back to its base value', () => {
9
- expect(fromFixedPoint(100_000_000n, 6)).toBe(100n)
10
- })
11
-
12
- it('should handle zero correctly', () => {
13
- expect(fromFixedPoint(0n, 6)).toBe(0n)
14
- })
15
-
16
- it('should handle large values correctly', () => {
17
- expect(fromFixedPoint(987_654_321_123_456_789n, 9)).toBe(987_654_321n)
18
- })
19
-
20
- it('should handle small values correctly', () => {
21
- expect(fromFixedPoint(1_234_567n, 6)).toBe(1n)
22
- })
23
-
24
- it('should handle cases where division results in truncation', () => {
25
- expect(fromFixedPoint(1_234_567n, 9)).toBe(0n)
26
- })
27
-
28
- it('should correctly process negative values', () => {
29
- expect(fromFixedPoint(-1_230_000n, 6)).toBe(-1n)
30
- })
31
-
32
- it('should throw an error for non-integer places', () => {
33
- expect(() => fromFixedPoint(1_000_000n, 2.5)).toThrow('places (2.5) must be an Integer')
34
- })
35
- })
@@ -1,51 +0,0 @@
1
- import {
2
- describe, expect, it,
3
- } from 'vitest'
4
-
5
- import { toDecimalPrecision } from '../toDecimalPrecision.ts'
6
-
7
- describe('toDecimalPrecision', () => {
8
- it('should return a string representation of a number with specified precision', () => {
9
- expect(toDecimalPrecision(1.234_567_89, 3)).toBe('1.23')
10
- expect(toDecimalPrecision(1234.567_89, 5)).toBe('1234.6')
11
- })
12
-
13
- it('should handle rounding correctly', () => {
14
- expect(toDecimalPrecision(1.999_99, 2)).toBe('2')
15
- expect(toDecimalPrecision(9.876_543_21, 3)).toBe('9.88')
16
- })
17
-
18
- it('should round to the closest number at the midpoint', () => {
19
- expect(toDecimalPrecision(1.2351, 3)).toBe('1.24')
20
- expect(toDecimalPrecision(1.235, 3)).toBe('1.24')
21
- expect(toDecimalPrecision(1.2349, 3)).toBe('1.23')
22
- })
23
-
24
- it('should remove insignificant digits', () => {
25
- expect(toDecimalPrecision(1.000_000_000_000_000_000_000_1, 3)).toBe('1')
26
- })
27
-
28
- it('should handle whole numbers correctly', () => {
29
- expect(toDecimalPrecision(100, 5)).toBe('100')
30
- })
31
-
32
- it('should handle small numbers correctly', () => {
33
- expect(toDecimalPrecision(0.000_123_456_789, 4)).toBe('0.0001235')
34
- })
35
-
36
- it('should handle big and small numbers correctly', () => {
37
- expect(toDecimalPrecision(0.000_123_456, 4)).toBe('0.0001235')
38
- })
39
-
40
- it('should handle negative numbers correctly', () => {
41
- expect(toDecimalPrecision(-1.234_567_89, 4)).toBe('-1.235')
42
- })
43
-
44
- it('should handle zero correctly', () => {
45
- expect(toDecimalPrecision(0, 5)).toBe('0')
46
- })
47
-
48
- it('should handle edge cases with very small numbers', () => {
49
- expect(toDecimalPrecision(1e-10, 2)).toBe('0.0000000001')
50
- })
51
- })
@@ -1,52 +0,0 @@
1
- import {
2
- describe, expect, it,
3
- } from 'vitest'
4
-
5
- import { toFixedPoint } from '../toFixedPoint.ts'
6
-
7
- describe('toFixedPoint', () => {
8
- it('should convert an integer bigint to fixed point', () => {
9
- expect(toFixedPoint(100n, 6)).toBe(100_000_000n)
10
- })
11
-
12
- it('should convert an integer string to fixed point', () => {
13
- expect(toFixedPoint('100', 6)).toBe(100_000_000n)
14
- })
15
-
16
- it('should convert a decimal string to fixed point', () => {
17
- expect(toFixedPoint('1.23', 6)).toBe(1_230_000n)
18
- })
19
-
20
- it('should handle cases with more decimal places than specified', () => {
21
- expect(toFixedPoint('1.23456789', 6)).toBe(1_234_567n)
22
- })
23
-
24
- it('should handle cases with fewer decimal places than specified', () => {
25
- expect(toFixedPoint('1.2', 6)).toBe(1_200_000n)
26
- })
27
-
28
- it('should handle zero correctly', () => {
29
- expect(toFixedPoint('0', 6)).toBe(0n)
30
- expect(toFixedPoint('0.0', 6)).toBe(0n)
31
- })
32
-
33
- it('should throw an error for non-integer places', () => {
34
- expect(() => toFixedPoint('1.23', 2.5)).toThrow('places (2.5) must be an Integer')
35
- })
36
-
37
- it('should throw an error for malformed decimal strings', () => {
38
- expect(() => toFixedPoint('1.2.3', 6)).toThrow('Too many decimals in value')
39
- })
40
-
41
- it('should correctly pad shorter decimal strings', () => {
42
- expect(toFixedPoint('1.1', 4)).toBe(11_000n)
43
- })
44
-
45
- it('should correctly handle large values', () => {
46
- expect(toFixedPoint('987654321.123456789', 9)).toBe(987_654_321_123_456_789n)
47
- })
48
-
49
- it('should correctly handle negative values', () => {
50
- expect(toFixedPoint('-1.23', 6)).toBe(-1_230_000n)
51
- })
52
- })