ts-data-forge 11.0.0 → 12.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/README.md +2 -2
- package/dist/number/branded-types/finite-number.d.mts +47 -61
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +37 -41
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +40 -46
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +29 -31
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +71 -59
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +56 -47
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +71 -59
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +56 -47
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +62 -49
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +66 -49
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +48 -39
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +49 -44
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +55 -45
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +55 -46
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +46 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +33 -108
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +51 -38
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +31 -27
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +44 -41
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +44 -42
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +67 -52
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +53 -70
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +42 -52
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +68 -58
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +52 -45
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +68 -58
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +52 -45
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +56 -48
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +68 -58
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +52 -45
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +68 -59
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +52 -46
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +52 -66
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +45 -47
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +68 -58
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +53 -46
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +72 -55
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +52 -45
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +66 -59
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +51 -45
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +66 -57
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +50 -45
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +62 -66
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +57 -51
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +66 -59
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +57 -51
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +9 -9
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +7 -7
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/package.json +2 -1
- package/src/number/branded-types/finite-number.mts +47 -61
- package/src/number/branded-types/int.mts +40 -46
- package/src/number/branded-types/int16.mts +72 -60
- package/src/number/branded-types/int32.mts +72 -60
- package/src/number/branded-types/negative-finite-number.mts +78 -71
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +68 -60
- package/src/number/branded-types/negative-int.test.mts +5 -5
- package/src/number/branded-types/negative-safe-int.mts +66 -68
- package/src/number/branded-types/negative-safe-int.test.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +81 -66
- package/src/number/branded-types/non-negative-int16.mts +72 -59
- package/src/number/branded-types/non-negative-int32.mts +72 -60
- package/src/number/branded-types/non-positive-finite-number.mts +71 -56
- package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
- package/src/number/branded-types/non-positive-int.mts +47 -147
- package/src/number/branded-types/non-positive-int.test.mts +7 -7
- package/src/number/branded-types/non-positive-safe-int.mts +63 -55
- package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
- package/src/number/branded-types/non-zero-finite-number.mts +62 -51
- package/src/number/branded-types/non-zero-int.mts +51 -38
- package/src/number/branded-types/non-zero-int16.mts +60 -55
- package/src/number/branded-types/non-zero-int32.mts +60 -56
- package/src/number/branded-types/non-zero-safe-int.mts +61 -56
- package/src/number/branded-types/non-zero-uint16.mts +60 -55
- package/src/number/branded-types/non-zero-uint32.mts +60 -55
- package/src/number/branded-types/positive-finite-number.mts +83 -65
- package/src/number/branded-types/positive-int.mts +54 -71
- package/src/number/branded-types/positive-int16.mts +69 -59
- package/src/number/branded-types/positive-int32.mts +69 -59
- package/src/number/branded-types/positive-safe-int.mts +73 -62
- package/src/number/branded-types/positive-uint16.mts +69 -59
- package/src/number/branded-types/positive-uint32.mts +69 -60
- package/src/number/branded-types/safe-int.mts +53 -67
- package/src/number/branded-types/safe-uint.mts +69 -59
- package/src/number/branded-types/uint.mts +73 -56
- package/src/number/branded-types/uint16.mts +67 -60
- package/src/number/branded-types/uint32.mts +67 -58
- package/src/number/enum/int8.mts +70 -73
- package/src/number/enum/int8.test.mts +7 -4
- package/src/number/enum/uint8.mts +74 -66
- package/src/number/enum/uint8.test.mts +7 -4
- package/src/number/refined-number-utils.mts +22 -19
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
MAX_VALUE,
|
|
7
7
|
add,
|
|
8
8
|
castType,
|
|
9
|
-
|
|
9
|
+
fromNumber,
|
|
10
10
|
is,
|
|
11
11
|
max: max_,
|
|
12
12
|
min: min_,
|
|
@@ -19,7 +19,7 @@ const {
|
|
|
19
19
|
MAX_VALUE: -Number.MIN_VALUE,
|
|
20
20
|
typeNameInMessage
|
|
21
21
|
});
|
|
22
|
-
const abs = (x) => PositiveFiniteNumber.
|
|
22
|
+
const abs = (x) => PositiveFiniteNumber.fromNumber(Math.abs(x));
|
|
23
23
|
const floor = (x) => (
|
|
24
24
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
25
|
Math.floor(x)
|
|
@@ -38,101 +38,114 @@ const isNegativeFiniteNumber = is;
|
|
|
38
38
|
const asNegativeFiniteNumber = castType;
|
|
39
39
|
const NegativeFiniteNumber = {
|
|
40
40
|
/**
|
|
41
|
-
* Type guard
|
|
41
|
+
* Type guard that checks if a value is a negative finite number.
|
|
42
42
|
*
|
|
43
|
-
* @param value The value to check
|
|
44
|
-
* @returns `true` if the value is a negative finite number, `false`
|
|
45
|
-
*
|
|
43
|
+
* @param value - The value to check
|
|
44
|
+
* @returns `true` if the value is a negative finite number, `false` otherwise
|
|
45
|
+
* @see {@link isNegativeFiniteNumber} for usage examples
|
|
46
46
|
*/
|
|
47
47
|
is,
|
|
48
48
|
/**
|
|
49
|
-
* The
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* The largest value representable as `NegativeFiniteNumber` (the upper
|
|
50
|
+
* saturation target of `fromNumber`). The domain is open at `0` (excluded),
|
|
51
|
+
* so this is `-Number.MIN_VALUE` — the negative double closest to `0` —
|
|
52
|
+
* rather than `0`.
|
|
52
53
|
*/
|
|
53
54
|
MAX_VALUE,
|
|
54
55
|
/**
|
|
55
56
|
* Returns the absolute value of a negative finite number.
|
|
56
57
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
58
|
+
* The result is non-negative and keeps the `NegativeFiniteNumber` brand.
|
|
59
|
+
*
|
|
60
|
+
* @param a - The negative finite number value
|
|
61
|
+
* @returns The absolute value as a non-negative `NegativeFiniteNumber`
|
|
59
62
|
*/
|
|
60
63
|
abs,
|
|
61
64
|
/**
|
|
62
|
-
* Returns the
|
|
65
|
+
* Returns the smallest of the given negative finite numbers.
|
|
63
66
|
*
|
|
64
|
-
* @param
|
|
65
|
-
* @
|
|
66
|
-
* @returns The minimum value as a NegativeFiniteNumber.
|
|
67
|
+
* @param values - The negative finite numbers to compare (at least one required)
|
|
68
|
+
* @returns The smallest value as a `NegativeFiniteNumber`
|
|
67
69
|
*/
|
|
68
70
|
min: min_,
|
|
69
71
|
/**
|
|
70
|
-
* Returns the
|
|
72
|
+
* Returns the largest of the given negative finite numbers.
|
|
71
73
|
*
|
|
72
|
-
* @param
|
|
73
|
-
* @
|
|
74
|
-
* @returns The maximum value as a NegativeFiniteNumber.
|
|
74
|
+
* @param values - The negative finite numbers to compare (at least one required)
|
|
75
|
+
* @returns The largest value as a `NegativeFiniteNumber`
|
|
75
76
|
*/
|
|
76
77
|
max: max_,
|
|
77
78
|
/**
|
|
78
|
-
*
|
|
79
|
+
* Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it
|
|
80
|
+
* into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
81
|
+
*
|
|
82
|
+
* Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are
|
|
83
|
+
* clamped to the nearest representable `NegativeFiniteNumber` instead of
|
|
84
|
+
* throwing.
|
|
79
85
|
*
|
|
80
|
-
* @param value The
|
|
81
|
-
* @returns The value
|
|
86
|
+
* @param value - The value to convert
|
|
87
|
+
* @returns The value as a `NegativeFiniteNumber`
|
|
82
88
|
*/
|
|
83
|
-
|
|
89
|
+
fromNumber,
|
|
84
90
|
/**
|
|
85
|
-
*
|
|
91
|
+
* Returns the greatest integer less than or equal to a negative finite
|
|
92
|
+
* number.
|
|
86
93
|
*
|
|
87
|
-
* @param
|
|
88
|
-
* @returns The
|
|
94
|
+
* @param a - The negative finite number value
|
|
95
|
+
* @returns The floored value as an integer
|
|
89
96
|
*/
|
|
90
97
|
floor,
|
|
91
98
|
/**
|
|
92
|
-
*
|
|
99
|
+
* Returns the smallest integer greater than or equal to a negative finite
|
|
100
|
+
* number.
|
|
93
101
|
*
|
|
94
|
-
* @param
|
|
95
|
-
* @returns The
|
|
102
|
+
* @param a - The negative finite number value
|
|
103
|
+
* @returns The ceiled value as an integer
|
|
96
104
|
*/
|
|
97
105
|
ceil,
|
|
98
106
|
/**
|
|
99
|
-
*
|
|
107
|
+
* Returns the value of a negative finite number rounded to the nearest
|
|
108
|
+
* integer.
|
|
100
109
|
*
|
|
101
|
-
* @param
|
|
102
|
-
* @returns The rounded value as
|
|
110
|
+
* @param a - The negative finite number value
|
|
111
|
+
* @returns The rounded value as an integer
|
|
103
112
|
*/
|
|
104
113
|
round,
|
|
105
114
|
/**
|
|
106
|
-
* Generates a random NegativeFiniteNumber
|
|
115
|
+
* Generates a random `NegativeFiniteNumber` within the given range.
|
|
107
116
|
*
|
|
108
|
-
*
|
|
117
|
+
* The range is inclusive on both ends.
|
|
118
|
+
*
|
|
119
|
+
* @param min - The minimum value (inclusive)
|
|
120
|
+
* @param max - The maximum value (inclusive)
|
|
121
|
+
* @returns A random `NegativeFiniteNumber` in `[min, max]`
|
|
109
122
|
*/
|
|
110
123
|
random,
|
|
111
124
|
/**
|
|
112
|
-
* Raises a
|
|
125
|
+
* Raises `a` to the power `b`, returning `a ** b` as a
|
|
126
|
+
* `NegativeFiniteNumber`.
|
|
113
127
|
*
|
|
114
|
-
* @param a The base
|
|
115
|
-
* @param b The exponent
|
|
116
|
-
* @returns `a ** b`
|
|
128
|
+
* @param a - The base negative finite number
|
|
129
|
+
* @param b - The exponent negative finite number
|
|
130
|
+
* @returns `a ** b` as a `NegativeFiniteNumber`
|
|
117
131
|
*/
|
|
118
132
|
pow,
|
|
119
133
|
/**
|
|
120
|
-
* Adds two
|
|
134
|
+
* Adds two negative finite numbers, returning `a + b` as a
|
|
135
|
+
* `NegativeFiniteNumber`.
|
|
121
136
|
*
|
|
122
|
-
* @param a The first
|
|
123
|
-
* @param b The second
|
|
124
|
-
* @returns `a
|
|
137
|
+
* @param a - The first negative finite number
|
|
138
|
+
* @param b - The second negative finite number
|
|
139
|
+
* @returns The sum of `a` and `b` as a `NegativeFiniteNumber`
|
|
125
140
|
*/
|
|
126
141
|
add,
|
|
127
142
|
/**
|
|
128
|
-
* Subtracts
|
|
129
|
-
*
|
|
130
|
-
* The mathematical result can be positive, so it is clamped to the negative
|
|
131
|
-
* finite range (maximum `-Number.MIN_VALUE`).
|
|
143
|
+
* Subtracts two negative finite numbers, returning `a - b` as a
|
|
144
|
+
* `NegativeFiniteNumber`.
|
|
132
145
|
*
|
|
133
|
-
* @param a The
|
|
134
|
-
* @param b The
|
|
135
|
-
* @returns
|
|
146
|
+
* @param a - The first negative finite number
|
|
147
|
+
* @param b - The second negative finite number
|
|
148
|
+
* @returns The difference of `a` and `b` as a `NegativeFiniteNumber`
|
|
136
149
|
*/
|
|
137
150
|
sub
|
|
138
151
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-finite-number.mjs","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"sourcesContent":["import { type NegativeFiniteNumber as TtfImported_NegativeFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveFiniteNumber } from './positive-finite-number.mjs';\n\nexport type NegativeFiniteNumber = TtfImported_NegativeFiniteNumber;\n\ntype ElementType = NegativeFiniteNumber;\n\nconst typeNameInMessage = 'a negative finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"negative-finite-number.mjs","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"sourcesContent":["import { type NegativeFiniteNumber as TtfImported_NegativeFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveFiniteNumber } from './positive-finite-number.mjs';\n\nexport type NegativeFiniteNumber = TtfImported_NegativeFiniteNumber;\n\ntype ElementType = NegativeFiniteNumber;\n\nconst typeNameInMessage = 'a negative finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n ElementType,\n number,\n number\n>({\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -Number.MIN_VALUE,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: ElementType): PositiveFiniteNumber =>\n PositiveFiniteNumber.fromNumber(Math.abs(x));\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\n/**\n * Type guard that checks if a value is a negative finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n */\nexport const isNegativeFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NegativeFiniteNumber` branded type.\n *\n * Validates that the value is a negative finite number and returns it with the\n * `NegativeFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeFiniteNumber`\n * @throws {TypeError} If the value is not a negative finite number\n */\nexport const asNegativeFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeFiniteNumber`\n * branded type.\n *\n * The `NegativeFiniteNumber` type represents a negative finite number.\n */\nexport const NegativeFiniteNumber = {\n /**\n * Type guard that checks if a value is a negative finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n * @see {@link isNegativeFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeFiniteNumber` (the upper\n * saturation target of `fromNumber`). The domain is open at `0` (excluded),\n * so this is `-Number.MIN_VALUE` — the negative double closest to `0` —\n * rather than `0`.\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative finite number.\n *\n * The result is non-negative and keeps the `NegativeFiniteNumber` brand.\n *\n * @param a - The negative finite number value\n * @returns The absolute value as a non-negative `NegativeFiniteNumber`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The smallest value as a `NegativeFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The largest value as a `NegativeFiniteNumber`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it\n * into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are\n * clamped to the nearest representable `NegativeFiniteNumber` instead of\n * throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NegativeFiniteNumber`\n */\n fromNumber,\n\n /**\n * Returns the greatest integer less than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a negative finite number rounded to the nearest\n * integer.\n *\n * @param a - The negative finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NegativeFiniteNumber` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NegativeFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The base negative finite number\n * @param b - The exponent negative finite number\n * @returns `a ** b` as a `NegativeFiniteNumber`\n */\n pow,\n\n /**\n * Adds two negative finite numbers, returning `a + b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The sum of `a` and `b` as a `NegativeFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two negative finite numbers, returning `a - b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The difference of `a` and `b` as a `NegativeFiniteNumber`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAQA,MAAM,iBAAA,GAAoB,0BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,iBAAA,CAI1C;AAAA,EACA,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,oBAAA,CAAqB,WAAW,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAE7C,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAEd,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAIb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAaK,MAAM,sBAAA,GAAyB;AAY/B,MAAM,sBAAA,GAAyB;AAQ/B,MAAM,oBAAA,GAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|
|
@@ -3,18 +3,24 @@ import { PositiveInt } from './positive-int.mjs';
|
|
|
3
3
|
export type NegativeInt = TtfImported_NegativeInt;
|
|
4
4
|
type ElementType = NegativeInt;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Type guard that checks if a value is a negative integer.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Returns `true` for a negative integer — a value with no fractional component,
|
|
9
|
+
* including values outside the safe integer range (unlike `SafeInt`).
|
|
10
|
+
*
|
|
11
|
+
* @param value - The value to check
|
|
12
|
+
* @returns `true` if the value is a negative integer, `false` otherwise
|
|
10
13
|
*/
|
|
11
14
|
export declare const isNegativeInt: (a: number) => a is TtfImported_NegativeInt;
|
|
12
15
|
/**
|
|
13
|
-
* Casts a number to
|
|
16
|
+
* Casts a `number` to the `NegativeInt` branded type.
|
|
17
|
+
*
|
|
18
|
+
* Validates that the value is a negative integer and returns it with the
|
|
19
|
+
* `NegativeInt` brand. Throws a `TypeError` otherwise.
|
|
14
20
|
*
|
|
15
|
-
* @param value The value to cast
|
|
16
|
-
* @returns The value as a NegativeInt
|
|
17
|
-
* @throws {TypeError} If the value is not a negative integer
|
|
21
|
+
* @param value - The value to cast
|
|
22
|
+
* @returns The value as a `NegativeInt`
|
|
23
|
+
* @throws {TypeError} If the value is not a negative integer
|
|
18
24
|
*/
|
|
19
25
|
export declare const asNegativeInt: <N extends number>(x: N) => number & {
|
|
20
26
|
readonly "!=0": true;
|
|
@@ -31,88 +37,99 @@ export declare const asNegativeInt: <N extends number>(x: N) => number & {
|
|
|
31
37
|
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
32
38
|
}> & N;
|
|
33
39
|
/**
|
|
34
|
-
* Namespace providing type-safe
|
|
40
|
+
* Namespace providing type-safe operations for the `NegativeInt` branded type.
|
|
35
41
|
*
|
|
36
|
-
* NegativeInt represents
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
42
|
+
* The `NegativeInt` type represents a negative integer. Division (`div`) uses
|
|
43
|
+
* floor division.
|
|
44
|
+
*
|
|
45
|
+
* Unlike `SafeInt`, `NegativeInt` allows values outside the safe integer range
|
|
46
|
+
* (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's
|
|
47
|
+
* `number` type.
|
|
40
48
|
*/
|
|
41
49
|
export declare const NegativeInt: {
|
|
42
50
|
/**
|
|
43
|
-
* Type guard
|
|
51
|
+
* Type guard that checks if a value is a negative integer.
|
|
44
52
|
*
|
|
45
|
-
* @param value The value to check
|
|
46
|
-
* @returns `true` if the value is a negative integer, `false` otherwise
|
|
53
|
+
* @param value - The value to check
|
|
54
|
+
* @returns `true` if the value is a negative integer, `false` otherwise
|
|
55
|
+
* @see {@link isNegativeInt} for usage examples
|
|
47
56
|
*/
|
|
48
57
|
readonly is: (a: number) => a is TtfImported_NegativeInt;
|
|
49
58
|
/**
|
|
50
|
-
* The
|
|
51
|
-
*
|
|
52
|
-
* @readonly
|
|
59
|
+
* The largest value representable as `NegativeInt` (the upper saturation
|
|
60
|
+
* target of `fromNumber`).
|
|
53
61
|
*/
|
|
54
62
|
readonly MAX_VALUE: -1;
|
|
55
63
|
/**
|
|
56
64
|
* Returns the absolute value of a negative integer.
|
|
57
65
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
66
|
+
* The result is non-negative and keeps the `NegativeInt` brand. Note that
|
|
67
|
+
* `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
|
|
68
|
+
* use `SafeInt` for guaranteed precision.
|
|
69
|
+
*
|
|
70
|
+
* @param a - The negative integer value
|
|
71
|
+
* @returns The absolute value as a non-negative `NegativeInt`
|
|
60
72
|
*/
|
|
61
73
|
readonly abs: (x: WithSmallInt<ElementType>) => PositiveInt;
|
|
62
74
|
/**
|
|
63
|
-
* Returns the
|
|
75
|
+
* Returns the smallest of the given negative integers.
|
|
64
76
|
*
|
|
65
|
-
* @param
|
|
66
|
-
* @
|
|
67
|
-
* @returns The minimum value as a NegativeInt.
|
|
77
|
+
* @param values - The negative integers to compare (at least one required)
|
|
78
|
+
* @returns The smallest value as a `NegativeInt`
|
|
68
79
|
*/
|
|
69
80
|
readonly min: (...values: readonly WithSmallInt<TtfImported_NegativeInt>[]) => TtfImported_NegativeInt;
|
|
70
81
|
/**
|
|
71
|
-
* Returns the
|
|
82
|
+
* Returns the largest of the given negative integers.
|
|
72
83
|
*
|
|
73
|
-
* @param
|
|
74
|
-
* @
|
|
75
|
-
* @returns The maximum value as a NegativeInt.
|
|
84
|
+
* @param values - The negative integers to compare (at least one required)
|
|
85
|
+
* @returns The largest value as a `NegativeInt`
|
|
76
86
|
*/
|
|
77
87
|
readonly max: (...values: readonly WithSmallInt<TtfImported_NegativeInt>[]) => TtfImported_NegativeInt;
|
|
78
88
|
/**
|
|
79
|
-
*
|
|
89
|
+
* Converts an arbitrary `number` into a `NegativeInt`, rounding to the
|
|
90
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
91
|
+
* MAX_VALUE]`.
|
|
92
|
+
*
|
|
93
|
+
* Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to
|
|
94
|
+
* the nearest representable `NegativeInt` instead of throwing.
|
|
80
95
|
*
|
|
81
|
-
* @param value The
|
|
82
|
-
* @returns The value
|
|
96
|
+
* @param value - The value to convert
|
|
97
|
+
* @returns The value as a `NegativeInt`
|
|
83
98
|
*/
|
|
84
|
-
readonly
|
|
99
|
+
readonly fromNumber: (x: number) => TtfImported_NegativeInt;
|
|
85
100
|
/**
|
|
86
|
-
* Generates a random NegativeInt
|
|
101
|
+
* Generates a random `NegativeInt` within the given range.
|
|
87
102
|
*
|
|
88
|
-
*
|
|
103
|
+
* The range is inclusive on both ends.
|
|
104
|
+
*
|
|
105
|
+
* @param min - The minimum value (inclusive)
|
|
106
|
+
* @param max - The maximum value (inclusive)
|
|
107
|
+
* @returns A random `NegativeInt` in `[min, max]`
|
|
89
108
|
*/
|
|
90
109
|
readonly random: (min?: WithSmallInt<TtfImported_NegativeInt> | undefined, max?: WithSmallInt<TtfImported_NegativeInt> | undefined) => TtfImported_NegativeInt;
|
|
91
110
|
/**
|
|
92
|
-
* Raises a
|
|
111
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored
|
|
112
|
+
* to an integer).
|
|
93
113
|
*
|
|
94
|
-
* @param a The base negative integer
|
|
95
|
-
* @param b The exponent negative integer
|
|
96
|
-
* @returns `a ** b`
|
|
114
|
+
* @param a - The base negative integer
|
|
115
|
+
* @param b - The exponent negative integer
|
|
116
|
+
* @returns `a ** b` as a `NegativeInt`
|
|
97
117
|
*/
|
|
98
118
|
readonly pow: (x: WithSmallInt<TtfImported_NegativeInt>, y: WithSmallInt<TtfImported_NegativeInt>) => TtfImported_NegativeInt;
|
|
99
119
|
/**
|
|
100
|
-
* Adds two negative integers
|
|
120
|
+
* Adds two negative integers, returning `a + b` as a `NegativeInt`.
|
|
101
121
|
*
|
|
102
|
-
* @param a The first negative integer
|
|
103
|
-
* @param b The second negative integer
|
|
104
|
-
* @returns `a
|
|
122
|
+
* @param a - The first negative integer
|
|
123
|
+
* @param b - The second negative integer
|
|
124
|
+
* @returns The sum of `a` and `b` as a `NegativeInt`
|
|
105
125
|
*/
|
|
106
126
|
readonly add: (x: WithSmallInt<TtfImported_NegativeInt>, y: WithSmallInt<TtfImported_NegativeInt>) => TtfImported_NegativeInt;
|
|
107
127
|
/**
|
|
108
|
-
* Subtracts
|
|
109
|
-
*
|
|
110
|
-
* The mathematical result can be positive, so it is clamped to the negative
|
|
111
|
-
* integer range (maximum `-1`).
|
|
128
|
+
* Subtracts two negative integers, returning `a - b` as a `NegativeInt`.
|
|
112
129
|
*
|
|
113
|
-
* @param a The
|
|
114
|
-
* @param b The
|
|
115
|
-
* @returns `a
|
|
130
|
+
* @param a - The first negative integer
|
|
131
|
+
* @param b - The second negative integer
|
|
132
|
+
* @returns The difference of `a` and `b` as a `NegativeInt`
|
|
116
133
|
*/
|
|
117
134
|
readonly sub: (x: WithSmallInt<TtfImported_NegativeInt>, y: WithSmallInt<TtfImported_NegativeInt>) => TtfImported_NegativeInt;
|
|
118
135
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,IAAI,uBAAuB,EAC3C,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAElD,KAAK,WAAW,GAAG,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"negative-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,IAAI,uBAAuB,EAC3C,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAElD,KAAK,WAAW,GAAG,WAAW,CAAC;AA8B/B;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;MAAW,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;;;;;;;OASG;sBA7DW,YAAY,CAAC,WAAW,CAAC,KAAG,WAAW;IAgErD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAEK,CAAC"}
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
MAX_VALUE,
|
|
7
7
|
add,
|
|
8
8
|
castType,
|
|
9
|
-
|
|
9
|
+
fromNumber,
|
|
10
10
|
is,
|
|
11
11
|
max: max_,
|
|
12
12
|
min: min_,
|
|
@@ -20,84 +20,93 @@ const {
|
|
|
20
20
|
MAX_VALUE: -1,
|
|
21
21
|
typeNameInMessage
|
|
22
22
|
});
|
|
23
|
-
const abs = (x) => PositiveInt.
|
|
23
|
+
const abs = (x) => PositiveInt.fromNumber(Math.abs(x));
|
|
24
24
|
const isNegativeInt = is;
|
|
25
25
|
const asNegativeInt = castType;
|
|
26
26
|
const NegativeInt = {
|
|
27
27
|
/**
|
|
28
|
-
* Type guard
|
|
28
|
+
* Type guard that checks if a value is a negative integer.
|
|
29
29
|
*
|
|
30
|
-
* @param value The value to check
|
|
31
|
-
* @returns `true` if the value is a negative integer, `false` otherwise
|
|
30
|
+
* @param value - The value to check
|
|
31
|
+
* @returns `true` if the value is a negative integer, `false` otherwise
|
|
32
|
+
* @see {@link isNegativeInt} for usage examples
|
|
32
33
|
*/
|
|
33
34
|
is,
|
|
34
35
|
/**
|
|
35
|
-
* The
|
|
36
|
-
*
|
|
37
|
-
* @readonly
|
|
36
|
+
* The largest value representable as `NegativeInt` (the upper saturation
|
|
37
|
+
* target of `fromNumber`).
|
|
38
38
|
*/
|
|
39
39
|
MAX_VALUE,
|
|
40
40
|
/**
|
|
41
41
|
* Returns the absolute value of a negative integer.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* The result is non-negative and keeps the `NegativeInt` brand. Note that
|
|
44
|
+
* `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
|
|
45
|
+
* use `SafeInt` for guaranteed precision.
|
|
46
|
+
*
|
|
47
|
+
* @param a - The negative integer value
|
|
48
|
+
* @returns The absolute value as a non-negative `NegativeInt`
|
|
45
49
|
*/
|
|
46
50
|
abs,
|
|
47
51
|
/**
|
|
48
|
-
* Returns the
|
|
52
|
+
* Returns the smallest of the given negative integers.
|
|
49
53
|
*
|
|
50
|
-
* @param
|
|
51
|
-
* @
|
|
52
|
-
* @returns The minimum value as a NegativeInt.
|
|
54
|
+
* @param values - The negative integers to compare (at least one required)
|
|
55
|
+
* @returns The smallest value as a `NegativeInt`
|
|
53
56
|
*/
|
|
54
57
|
min: min_,
|
|
55
58
|
/**
|
|
56
|
-
* Returns the
|
|
59
|
+
* Returns the largest of the given negative integers.
|
|
57
60
|
*
|
|
58
|
-
* @param
|
|
59
|
-
* @
|
|
60
|
-
* @returns The maximum value as a NegativeInt.
|
|
61
|
+
* @param values - The negative integers to compare (at least one required)
|
|
62
|
+
* @returns The largest value as a `NegativeInt`
|
|
61
63
|
*/
|
|
62
64
|
max: max_,
|
|
63
65
|
/**
|
|
64
|
-
*
|
|
66
|
+
* Converts an arbitrary `number` into a `NegativeInt`, rounding to the
|
|
67
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
68
|
+
* MAX_VALUE]`.
|
|
69
|
+
*
|
|
70
|
+
* Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to
|
|
71
|
+
* the nearest representable `NegativeInt` instead of throwing.
|
|
65
72
|
*
|
|
66
|
-
* @param value The
|
|
67
|
-
* @returns The value
|
|
73
|
+
* @param value - The value to convert
|
|
74
|
+
* @returns The value as a `NegativeInt`
|
|
68
75
|
*/
|
|
69
|
-
|
|
76
|
+
fromNumber,
|
|
70
77
|
/**
|
|
71
|
-
* Generates a random NegativeInt
|
|
78
|
+
* Generates a random `NegativeInt` within the given range.
|
|
72
79
|
*
|
|
73
|
-
*
|
|
80
|
+
* The range is inclusive on both ends.
|
|
81
|
+
*
|
|
82
|
+
* @param min - The minimum value (inclusive)
|
|
83
|
+
* @param max - The maximum value (inclusive)
|
|
84
|
+
* @returns A random `NegativeInt` in `[min, max]`
|
|
74
85
|
*/
|
|
75
86
|
random,
|
|
76
87
|
/**
|
|
77
|
-
* Raises a
|
|
88
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored
|
|
89
|
+
* to an integer).
|
|
78
90
|
*
|
|
79
|
-
* @param a The base negative integer
|
|
80
|
-
* @param b The exponent negative integer
|
|
81
|
-
* @returns `a ** b`
|
|
91
|
+
* @param a - The base negative integer
|
|
92
|
+
* @param b - The exponent negative integer
|
|
93
|
+
* @returns `a ** b` as a `NegativeInt`
|
|
82
94
|
*/
|
|
83
95
|
pow,
|
|
84
96
|
/**
|
|
85
|
-
* Adds two negative integers
|
|
97
|
+
* Adds two negative integers, returning `a + b` as a `NegativeInt`.
|
|
86
98
|
*
|
|
87
|
-
* @param a The first negative integer
|
|
88
|
-
* @param b The second negative integer
|
|
89
|
-
* @returns `a
|
|
99
|
+
* @param a - The first negative integer
|
|
100
|
+
* @param b - The second negative integer
|
|
101
|
+
* @returns The sum of `a` and `b` as a `NegativeInt`
|
|
90
102
|
*/
|
|
91
103
|
add,
|
|
92
104
|
/**
|
|
93
|
-
* Subtracts
|
|
94
|
-
*
|
|
95
|
-
* The mathematical result can be positive, so it is clamped to the negative
|
|
96
|
-
* integer range (maximum `-1`).
|
|
105
|
+
* Subtracts two negative integers, returning `a - b` as a `NegativeInt`.
|
|
97
106
|
*
|
|
98
|
-
* @param a The
|
|
99
|
-
* @param b The
|
|
100
|
-
* @returns `a
|
|
107
|
+
* @param a - The first negative integer
|
|
108
|
+
* @param b - The second negative integer
|
|
109
|
+
* @returns The difference of `a` and `b` as a `NegativeInt`
|
|
101
110
|
*/
|
|
102
111
|
sub
|
|
103
112
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-int.mjs","sources":["../../../src/number/branded-types/negative-int.mts"],"sourcesContent":["import {\n type NegativeInt as TtfImported_NegativeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveInt } from './positive-int.mjs';\n\nexport type NegativeInt = TtfImported_NegativeInt;\n\ntype ElementType = NegativeInt;\n\nconst typeNameInMessage = 'a negative integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"negative-int.mjs","sources":["../../../src/number/branded-types/negative-int.mts"],"sourcesContent":["import {\n type NegativeInt as TtfImported_NegativeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveInt } from './positive-int.mjs';\n\nexport type NegativeInt = TtfImported_NegativeInt;\n\ntype ElementType = NegativeInt;\n\nconst typeNameInMessage = 'a negative integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n -1\n>({\n integerOrSafeInteger: 'Integer',\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -1,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: WithSmallInt<ElementType>): PositiveInt =>\n PositiveInt.fromNumber(Math.abs(x));\n\n/**\n * Type guard that checks if a value is a negative integer.\n *\n * Returns `true` for a negative integer — a value with no fractional component,\n * including values outside the safe integer range (unlike `SafeInt`).\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n */\nexport const isNegativeInt = is;\n\n/**\n * Casts a `number` to the `NegativeInt` branded type.\n *\n * Validates that the value is a negative integer and returns it with the\n * `NegativeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeInt`\n * @throws {TypeError} If the value is not a negative integer\n */\nexport const asNegativeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeInt` branded type.\n *\n * The `NegativeInt` type represents a negative integer. Division (`div`) uses\n * floor division.\n *\n * Unlike `SafeInt`, `NegativeInt` allows values outside the safe integer range\n * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's\n * `number` type.\n */\nexport const NegativeInt = {\n /**\n * Type guard that checks if a value is a negative integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n * @see {@link isNegativeInt} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeInt` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative integer.\n *\n * The result is non-negative and keeps the `NegativeInt` brand. Note that\n * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so\n * use `SafeInt` for guaranteed precision.\n *\n * @param a - The negative integer value\n * @returns The absolute value as a non-negative `NegativeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The smallest value as a `NegativeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The largest value as a `NegativeInt`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NegativeInt`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to\n * the nearest representable `NegativeInt` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NegativeInt`\n */\n fromNumber,\n\n /**\n * Generates a random `NegativeInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NegativeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored\n * to an integer).\n *\n * @param a - The base negative integer\n * @param b - The exponent negative integer\n * @returns `a ** b` as a `NegativeInt`\n */\n pow,\n\n /**\n * Adds two negative integers, returning `a + b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The sum of `a` and `b` as a `NegativeInt`\n */\n add,\n\n /**\n * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The difference of `a` and `b` as a `NegativeInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAWA,MAAM,iBAAA,GAAoB,oBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,EAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,WAAA,CAAY,WAAW,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAW7B,MAAM,aAAA,GAAgB;AAYtB,MAAM,aAAA,GAAgB;AAYtB,MAAM,WAAA,GAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA;AACF;;;;"}
|