ts-data-forge 11.0.0 → 11.0.1

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.
Files changed (171) hide show
  1. package/dist/number/branded-types/finite-number.d.mts +47 -61
  2. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  3. package/dist/number/branded-types/finite-number.mjs +37 -41
  4. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  5. package/dist/number/branded-types/int.d.mts +40 -46
  6. package/dist/number/branded-types/int.d.mts.map +1 -1
  7. package/dist/number/branded-types/int.mjs +29 -31
  8. package/dist/number/branded-types/int.mjs.map +1 -1
  9. package/dist/number/branded-types/int16.d.mts +65 -58
  10. package/dist/number/branded-types/int16.d.mts.map +1 -1
  11. package/dist/number/branded-types/int16.mjs +49 -45
  12. package/dist/number/branded-types/int16.mjs.map +1 -1
  13. package/dist/number/branded-types/int32.d.mts +65 -58
  14. package/dist/number/branded-types/int32.d.mts.map +1 -1
  15. package/dist/number/branded-types/int32.mjs +49 -45
  16. package/dist/number/branded-types/int32.mjs.map +1 -1
  17. package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
  18. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  19. package/dist/number/branded-types/negative-finite-number.mjs +52 -46
  20. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  21. package/dist/number/branded-types/negative-int.d.mts +60 -48
  22. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  23. package/dist/number/branded-types/negative-int.mjs +40 -36
  24. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  25. package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
  26. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  27. package/dist/number/branded-types/negative-safe-int.mjs +40 -41
  28. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  29. package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
  30. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  31. package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
  32. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  33. package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
  34. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  35. package/dist/number/branded-types/non-negative-int16.mjs +47 -43
  36. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  37. package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
  38. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  39. package/dist/number/branded-types/non-negative-int32.mjs +47 -44
  40. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  41. package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
  42. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  43. package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
  44. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  45. package/dist/number/branded-types/non-positive-int.d.mts +41 -146
  46. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  47. package/dist/number/branded-types/non-positive-int.mjs +27 -107
  48. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  49. package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
  50. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  51. package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
  52. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  53. package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
  54. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  55. package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
  56. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  57. package/dist/number/branded-types/non-zero-int.d.mts +51 -38
  58. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  59. package/dist/number/branded-types/non-zero-int.mjs +31 -27
  60. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  61. package/dist/number/branded-types/non-zero-int16.d.mts +52 -53
  62. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  63. package/dist/number/branded-types/non-zero-int16.mjs +36 -39
  64. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  65. package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
  66. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  67. package/dist/number/branded-types/non-zero-int32.mjs +36 -40
  68. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  69. package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
  70. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  71. package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
  72. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  73. package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
  74. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  75. package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
  76. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  77. package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
  78. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  79. package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
  80. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  81. package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
  82. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  83. package/dist/number/branded-types/positive-finite-number.mjs +58 -50
  84. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  85. package/dist/number/branded-types/positive-int.d.mts +46 -68
  86. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  87. package/dist/number/branded-types/positive-int.mjs +34 -49
  88. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  89. package/dist/number/branded-types/positive-int16.d.mts +61 -57
  90. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  91. package/dist/number/branded-types/positive-int16.mjs +44 -43
  92. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  93. package/dist/number/branded-types/positive-int32.d.mts +61 -57
  94. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  95. package/dist/number/branded-types/positive-int32.mjs +44 -43
  96. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  97. package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
  98. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  99. package/dist/number/branded-types/positive-safe-int.mjs +45 -43
  100. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  101. package/dist/number/branded-types/positive-uint16.d.mts +61 -57
  102. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  103. package/dist/number/branded-types/positive-uint16.mjs +44 -43
  104. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  105. package/dist/number/branded-types/positive-uint32.d.mts +61 -58
  106. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  107. package/dist/number/branded-types/positive-uint32.mjs +44 -44
  108. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  109. package/dist/number/branded-types/safe-int.d.mts +43 -62
  110. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  111. package/dist/number/branded-types/safe-int.mjs +35 -42
  112. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  113. package/dist/number/branded-types/safe-uint.d.mts +62 -57
  114. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  115. package/dist/number/branded-types/safe-uint.mjs +46 -44
  116. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  117. package/dist/number/branded-types/uint.d.mts +63 -50
  118. package/dist/number/branded-types/uint.d.mts.map +1 -1
  119. package/dist/number/branded-types/uint.mjs +42 -39
  120. package/dist/number/branded-types/uint.mjs.map +1 -1
  121. package/dist/number/branded-types/uint16.d.mts +60 -58
  122. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  123. package/dist/number/branded-types/uint16.mjs +44 -43
  124. package/dist/number/branded-types/uint16.mjs.map +1 -1
  125. package/dist/number/branded-types/uint32.d.mts +59 -55
  126. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  127. package/dist/number/branded-types/uint32.mjs +42 -42
  128. package/dist/number/branded-types/uint32.mjs.map +1 -1
  129. package/dist/number/enum/int8.d.mts +56 -65
  130. package/dist/number/enum/int8.d.mts.map +1 -1
  131. package/dist/number/enum/int8.mjs +44 -43
  132. package/dist/number/enum/int8.mjs.map +1 -1
  133. package/dist/number/enum/uint8.d.mts +60 -58
  134. package/dist/number/enum/uint8.d.mts.map +1 -1
  135. package/dist/number/enum/uint8.mjs +44 -43
  136. package/dist/number/enum/uint8.mjs.map +1 -1
  137. package/package.json +2 -1
  138. package/src/number/branded-types/finite-number.mts +47 -61
  139. package/src/number/branded-types/int.mts +40 -46
  140. package/src/number/branded-types/int16.mts +65 -58
  141. package/src/number/branded-types/int32.mts +65 -58
  142. package/src/number/branded-types/negative-finite-number.mts +68 -68
  143. package/src/number/branded-types/negative-int.mts +60 -57
  144. package/src/number/branded-types/negative-safe-int.mts +57 -65
  145. package/src/number/branded-types/non-negative-finite-number.mts +74 -64
  146. package/src/number/branded-types/non-negative-int16.mts +64 -57
  147. package/src/number/branded-types/non-negative-int32.mts +64 -58
  148. package/src/number/branded-types/non-positive-finite-number.mts +64 -54
  149. package/src/number/branded-types/non-positive-int.mts +41 -146
  150. package/src/number/branded-types/non-positive-safe-int.mts +54 -53
  151. package/src/number/branded-types/non-zero-finite-number.mts +62 -51
  152. package/src/number/branded-types/non-zero-int.mts +51 -38
  153. package/src/number/branded-types/non-zero-int16.mts +52 -53
  154. package/src/number/branded-types/non-zero-int32.mts +52 -54
  155. package/src/number/branded-types/non-zero-safe-int.mts +53 -54
  156. package/src/number/branded-types/non-zero-uint16.mts +52 -53
  157. package/src/number/branded-types/non-zero-uint32.mts +52 -53
  158. package/src/number/branded-types/positive-finite-number.mts +74 -63
  159. package/src/number/branded-types/positive-int.mts +46 -68
  160. package/src/number/branded-types/positive-int16.mts +61 -57
  161. package/src/number/branded-types/positive-int32.mts +61 -57
  162. package/src/number/branded-types/positive-safe-int.mts +62 -57
  163. package/src/number/branded-types/positive-uint16.mts +61 -57
  164. package/src/number/branded-types/positive-uint32.mts +61 -58
  165. package/src/number/branded-types/safe-int.mts +43 -62
  166. package/src/number/branded-types/safe-uint.mts +62 -57
  167. package/src/number/branded-types/uint.mts +63 -50
  168. package/src/number/branded-types/uint16.mts +60 -58
  169. package/src/number/branded-types/uint32.mts +59 -55
  170. package/src/number/enum/int8.mts +56 -65
  171. package/src/number/enum/uint8.mts +60 -58
@@ -38,101 +38,107 @@ const isNegativeFiniteNumber = is;
38
38
  const asNegativeFiniteNumber = castType;
39
39
  const NegativeFiniteNumber = {
40
40
  /**
41
- * Type guard to check if a value is a NegativeFiniteNumber.
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
- * otherwise.
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 maximum value for a negative finite number.
50
- *
51
- * @readonly
49
+ * The largest value representable as `NegativeFiniteNumber`.
52
50
  */
53
51
  MAX_VALUE,
54
52
  /**
55
53
  * Returns the absolute value of a negative finite number.
56
54
  *
57
- * @param a The negative finite number.
58
- * @returns The absolute value as a PositiveFiniteNumber.
55
+ * The result is non-negative and keeps the `NegativeFiniteNumber` brand.
56
+ *
57
+ * @param a - The negative finite number value
58
+ * @returns The absolute value as a non-negative `NegativeFiniteNumber`
59
59
  */
60
60
  abs,
61
61
  /**
62
- * Returns the smaller of two NegativeFiniteNumber values.
62
+ * Returns the smallest of the given negative finite numbers.
63
63
  *
64
- * @param a The first NegativeFiniteNumber.
65
- * @param b The second NegativeFiniteNumber.
66
- * @returns The minimum value as a NegativeFiniteNumber.
64
+ * @param values - The negative finite numbers to compare (at least one required)
65
+ * @returns The smallest value as a `NegativeFiniteNumber`
67
66
  */
68
67
  min: min_,
69
68
  /**
70
- * Returns the larger of two NegativeFiniteNumber values.
69
+ * Returns the largest of the given negative finite numbers.
71
70
  *
72
- * @param a The first NegativeFiniteNumber.
73
- * @param b The second NegativeFiniteNumber.
74
- * @returns The maximum value as a NegativeFiniteNumber.
71
+ * @param values - The negative finite numbers to compare (at least one required)
72
+ * @returns The largest value as a `NegativeFiniteNumber`
75
73
  */
76
74
  max: max_,
77
75
  /**
78
- * Clamps a number to the negative finite range.
76
+ * Clamps a `number` into the `NegativeFiniteNumber` range `[MIN_VALUE,
77
+ * MAX_VALUE]`.
79
78
  *
80
- * @param value The number to clamp.
81
- * @returns The value clamped to `(-∞, 0)` as a NegativeFiniteNumber.
79
+ * @param value - The value to clamp
80
+ * @returns The clamped value as a `NegativeFiniteNumber`
82
81
  */
83
82
  clamp,
84
83
  /**
85
- * Rounds down a NegativeFiniteNumber to the nearest integer.
84
+ * Returns the greatest integer less than or equal to a negative finite
85
+ * number.
86
86
  *
87
- * @param x The NegativeFiniteNumber to round down.
88
- * @returns The floor value as a NegativeInt (always `<= -1`).
87
+ * @param a - The negative finite number value
88
+ * @returns The floored value as an integer
89
89
  */
90
90
  floor,
91
91
  /**
92
- * Rounds up a NegativeFiniteNumber to the nearest integer.
92
+ * Returns the smallest integer greater than or equal to a negative finite
93
+ * number.
93
94
  *
94
- * @param x The NegativeFiniteNumber to round up.
95
- * @returns The ceiling value as a NonPositiveInt (can be 0).
95
+ * @param a - The negative finite number value
96
+ * @returns The ceiled value as an integer
96
97
  */
97
98
  ceil,
98
99
  /**
99
- * Rounds a NegativeFiniteNumber to the nearest integer.
100
+ * Returns the value of a negative finite number rounded to the nearest
101
+ * integer.
100
102
  *
101
- * @param x The NegativeFiniteNumber to round.
102
- * @returns The rounded value as a NonPositiveInt (can be 0 if x > -0.5).
103
+ * @param a - The negative finite number value
104
+ * @returns The rounded value as an integer
103
105
  */
104
106
  round,
105
107
  /**
106
- * Generates a random NegativeFiniteNumber value.
108
+ * Generates a random `NegativeFiniteNumber` within the given range.
107
109
  *
108
- * @returns A random negative finite number.
110
+ * The range is inclusive on both ends.
111
+ *
112
+ * @param min - The minimum value (inclusive)
113
+ * @param max - The maximum value (inclusive)
114
+ * @returns A random `NegativeFiniteNumber` in `[min, max]`
109
115
  */
110
116
  random,
111
117
  /**
112
- * Raises a NegativeFiniteNumber to the power of another NegativeFiniteNumber.
118
+ * Raises `a` to the power `b`, returning `a ** b` as a
119
+ * `NegativeFiniteNumber`.
113
120
  *
114
- * @param a The base NegativeFiniteNumber.
115
- * @param b The exponent NegativeFiniteNumber.
116
- * @returns `a ** b` clamped to `(-∞, 0)` as a NegativeFiniteNumber.
121
+ * @param a - The base negative finite number
122
+ * @param b - The exponent negative finite number
123
+ * @returns `a ** b` as a `NegativeFiniteNumber`
117
124
  */
118
125
  pow,
119
126
  /**
120
- * Adds two NegativeFiniteNumber values.
127
+ * Adds two negative finite numbers, returning `a + b` as a
128
+ * `NegativeFiniteNumber`.
121
129
  *
122
- * @param a The first NegativeFiniteNumber.
123
- * @param b The second NegativeFiniteNumber.
124
- * @returns `a + b` as a NegativeFiniteNumber.
130
+ * @param a - The first negative finite number
131
+ * @param b - The second negative finite number
132
+ * @returns The sum of `a` and `b` as a `NegativeFiniteNumber`
125
133
  */
126
134
  add,
127
135
  /**
128
- * Subtracts one NegativeFiniteNumber from another.
129
- *
130
- * The mathematical result can be positive, so it is clamped to the negative
131
- * finite range (maximum `-Number.MIN_VALUE`).
136
+ * Subtracts two negative finite numbers, returning `a - b` as a
137
+ * `NegativeFiniteNumber`.
132
138
  *
133
- * @param a The minuend NegativeFiniteNumber.
134
- * @param b The subtrahend NegativeFiniteNumber.
135
- * @returns `a - b` clamped to `(-∞, 0)` as a NegativeFiniteNumber.
139
+ * @param a - The first negative finite number
140
+ * @param b - The second negative finite number
141
+ * @returns The difference of `a` and `b` as a `NegativeFiniteNumber`
136
142
  */
137
143
  sub
138
144
  };
@@ -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 clamp,\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\n/**\n * Returns the absolute value of a negative finite number.\n *\n * The absolute value of a negative finite number is always a positive finite\n * number, so the result is typed as a {@link PositiveFiniteNumber}.\n *\n * @param x - The negative finite number.\n * @returns `|x|` as a PositiveFiniteNumber.\n */\nconst abs = (x: ElementType): PositiveFiniteNumber =>\n PositiveFiniteNumber.clamp(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 * Checks if a number is a NegativeFiniteNumber (a finite number `< 0`).\n *\n * @param value The value to check.\n * @returns `true` if the value is a NegativeFiniteNumber, `false` otherwise.\n */\nexport const isNegativeFiniteNumber = is;\n\n/**\n * Casts a number to a NegativeFiniteNumber type.\n *\n * @param value The value to cast.\n * @returns The value as a NegativeFiniteNumber type.\n * @throws {TypeError} If the value is not a negative finite number.\n */\nexport const asNegativeFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe arithmetic operations for negative finite\n * numbers.\n *\n * All operations keep results finite (excluding NaN and Infinity). Operations\n * that stay within the negative finite numbers clamp their results to the valid\n * range, while operations whose result leaves the set (`mul`, `div`, `abs`) are\n * typed to reflect the actual sign of the result.\n */\nexport const NegativeFiniteNumber = {\n /**\n * Type guard to check if a value is a NegativeFiniteNumber.\n *\n * @param value The value to check.\n * @returns `true` if the value is a negative finite number, `false`\n * otherwise.\n */\n is,\n\n /**\n * The maximum value for a negative finite number.\n *\n * @readonly\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative finite number.\n *\n * @param a The negative finite number.\n * @returns The absolute value as a PositiveFiniteNumber.\n */\n abs,\n\n /**\n * Returns the smaller of two NegativeFiniteNumber values.\n *\n * @param a The first NegativeFiniteNumber.\n * @param b The second NegativeFiniteNumber.\n * @returns The minimum value as a NegativeFiniteNumber.\n */\n min: min_,\n\n /**\n * Returns the larger of two NegativeFiniteNumber values.\n *\n * @param a The first NegativeFiniteNumber.\n * @param b The second NegativeFiniteNumber.\n * @returns The maximum value as a NegativeFiniteNumber.\n */\n max: max_,\n\n /**\n * Clamps a number to the negative finite range.\n *\n * @param value The number to clamp.\n * @returns The value clamped to `(-∞, 0)` as a NegativeFiniteNumber.\n */\n clamp,\n\n /**\n * Rounds down a NegativeFiniteNumber to the nearest integer.\n *\n * @param x The NegativeFiniteNumber to round down.\n * @returns The floor value as a NegativeInt (always `<= -1`).\n */\n floor,\n\n /**\n * Rounds up a NegativeFiniteNumber to the nearest integer.\n *\n * @param x The NegativeFiniteNumber to round up.\n * @returns The ceiling value as a NonPositiveInt (can be 0).\n */\n ceil,\n\n /**\n * Rounds a NegativeFiniteNumber to the nearest integer.\n *\n * @param x The NegativeFiniteNumber to round.\n * @returns The rounded value as a NonPositiveInt (can be 0 if x > -0.5).\n */\n round,\n\n /**\n * Generates a random NegativeFiniteNumber value.\n *\n * @returns A random negative finite number.\n */\n random,\n\n /**\n * Raises a NegativeFiniteNumber to the power of another NegativeFiniteNumber.\n *\n * @param a The base NegativeFiniteNumber.\n * @param b The exponent NegativeFiniteNumber.\n * @returns `a ** b` clamped to `(-∞, 0)` as a NegativeFiniteNumber.\n */\n pow,\n\n /**\n * Adds two NegativeFiniteNumber values.\n *\n * @param a The first NegativeFiniteNumber.\n * @param b The second NegativeFiniteNumber.\n * @returns `a + b` as a NegativeFiniteNumber.\n */\n add,\n\n /**\n * Subtracts one NegativeFiniteNumber from another.\n *\n * The mathematical result can be positive, so it is clamped to the negative\n * finite range (maximum `-Number.MIN_VALUE`).\n *\n * @param a The minuend NegativeFiniteNumber.\n * @param b The subtrahend NegativeFiniteNumber.\n * @returns `a - b` clamped to `(-∞, 0)` 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,KAAA;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;AAWV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,oBAAA,CAAqB,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAExC,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;AAUK,MAAM,sBAAA,GAAyB;AAS/B,MAAM,sBAAA,GAAyB;AAW/B,MAAM,oBAAA,GAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AACF;;;;"}
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 clamp,\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.clamp(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`.\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 * Clamps a `number` into the `NegativeFiniteNumber` range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NegativeFiniteNumber`\n */\n clamp,\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,KAAA;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,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAExC,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,EAKA,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,EASL,KAAA;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
- * Checks if a number is a NegativeInt (a negative integer `<= -1`).
6
+ * Type guard that checks if a value is a negative integer.
7
7
  *
8
- * @param value The value to check.
9
- * @returns `true` if the value is a NegativeInt, `false` otherwise.
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 a NegativeInt type.
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 type.
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,94 @@ 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 arithmetic operations for negative integers.
40
+ * Namespace providing type-safe operations for the `NegativeInt` branded type.
35
41
  *
36
- * NegativeInt represents integers that are strictly less than zero (`<= -1`).
37
- * Operations that stay within the negative integers (such as `add`) clamp their
38
- * results to the valid range, while operations whose result leaves the set
39
- * (`mul`, `div`, `abs`) are typed to reflect the actual sign of the result.
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 to check if a value is a NegativeInt.
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 maximum value for a negative integer.
51
- *
52
- * @readonly
59
+ * The largest value representable as `NegativeInt`.
53
60
  */
54
61
  readonly MAX_VALUE: -1;
55
62
  /**
56
63
  * Returns the absolute value of a negative integer.
57
64
  *
58
- * @param a The negative integer.
59
- * @returns The absolute value as a PositiveInt.
65
+ * The result is non-negative and keeps the `NegativeInt` brand. Note that
66
+ * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
67
+ * use `SafeInt` for guaranteed precision.
68
+ *
69
+ * @param a - The negative integer value
70
+ * @returns The absolute value as a non-negative `NegativeInt`
60
71
  */
61
72
  readonly abs: (x: WithSmallInt<ElementType>) => PositiveInt;
62
73
  /**
63
- * Returns the smaller of two negative integers.
74
+ * Returns the smallest of the given negative integers.
64
75
  *
65
- * @param a The first negative integer.
66
- * @param b The second negative integer.
67
- * @returns The minimum value as a NegativeInt.
76
+ * @param values - The negative integers to compare (at least one required)
77
+ * @returns The smallest value as a `NegativeInt`
68
78
  */
69
79
  readonly min: (...values: readonly WithSmallInt<TtfImported_NegativeInt>[]) => TtfImported_NegativeInt;
70
80
  /**
71
- * Returns the larger of two negative integers.
81
+ * Returns the largest of the given negative integers.
72
82
  *
73
- * @param a The first negative integer.
74
- * @param b The second negative integer.
75
- * @returns The maximum value as a NegativeInt.
83
+ * @param values - The negative integers to compare (at least one required)
84
+ * @returns The largest value as a `NegativeInt`
76
85
  */
77
86
  readonly max: (...values: readonly WithSmallInt<TtfImported_NegativeInt>[]) => TtfImported_NegativeInt;
78
87
  /**
79
- * Clamps a number to the negative integer range.
88
+ * Clamps a `number` into the `NegativeInt` range, rounding to the nearest
89
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
80
90
  *
81
- * @param value The number to clamp.
82
- * @returns The value clamped to `[-∞, -1]` as a NegativeInt.
91
+ * @param value - The value to clamp
92
+ * @returns The clamped value as a `NegativeInt`
83
93
  */
84
94
  readonly clamp: (x: number) => TtfImported_NegativeInt;
85
95
  /**
86
- * Generates a random NegativeInt value within the valid range.
96
+ * Generates a random `NegativeInt` within the given range.
97
+ *
98
+ * The range is inclusive on both ends.
87
99
  *
88
- * @returns A random negative integer.
100
+ * @param min - The minimum value (inclusive)
101
+ * @param max - The maximum value (inclusive)
102
+ * @returns A random `NegativeInt` in `[min, max]`
89
103
  */
90
104
  readonly random: (min?: WithSmallInt<TtfImported_NegativeInt> | undefined, max?: WithSmallInt<TtfImported_NegativeInt> | undefined) => TtfImported_NegativeInt;
91
105
  /**
92
- * Raises a negative integer to the power of another negative integer.
106
+ * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored
107
+ * to an integer).
93
108
  *
94
- * @param a The base negative integer.
95
- * @param b The exponent negative integer.
96
- * @returns `a ** b` clamped to the negative integer range.
109
+ * @param a - The base negative integer
110
+ * @param b - The exponent negative integer
111
+ * @returns `a ** b` as a `NegativeInt`
97
112
  */
98
113
  readonly pow: (x: WithSmallInt<TtfImported_NegativeInt>, y: WithSmallInt<TtfImported_NegativeInt>) => TtfImported_NegativeInt;
99
114
  /**
100
- * Adds two negative integers.
115
+ * Adds two negative integers, returning `a + b` as a `NegativeInt`.
101
116
  *
102
- * @param a The first negative integer.
103
- * @param b The second negative integer.
104
- * @returns `a + b` as a NegativeInt.
117
+ * @param a - The first negative integer
118
+ * @param b - The second negative integer
119
+ * @returns The sum of `a` and `b` as a `NegativeInt`
105
120
  */
106
121
  readonly add: (x: WithSmallInt<TtfImported_NegativeInt>, y: WithSmallInt<TtfImported_NegativeInt>) => TtfImported_NegativeInt;
107
122
  /**
108
- * Subtracts one negative integer from another.
109
- *
110
- * The mathematical result can be positive, so it is clamped to the negative
111
- * integer range (maximum `-1`).
123
+ * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.
112
124
  *
113
- * @param a The minuend negative integer.
114
- * @param b The subtrahend negative integer.
115
- * @returns `a - b` clamped to the negative integer range.
125
+ * @param a - The first negative integer
126
+ * @param b - The second negative integer
127
+ * @returns The difference of `a` and `b` as a `NegativeInt`
116
128
  */
117
129
  readonly sub: (x: WithSmallInt<TtfImported_NegativeInt>, y: WithSmallInt<TtfImported_NegativeInt>) => TtfImported_NegativeInt;
118
130
  };
@@ -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;AAuC/B;;;;;GAKG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC;;;;;;GAMG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;MAAW,CAAC;AAEtC;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;;;OAKG;sBAjDW,YAAY,CAAC,WAAW,CAAC,KAAG,WAAW;IAoDrD;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;;OASG;;CAEK,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;;OAEG;;IAGH;;;;;;;;;OASG;sBA5DW,YAAY,CAAC,WAAW,CAAC,KAAG,WAAW;IA+DrD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAEK,CAAC"}
@@ -25,79 +25,83 @@ const isNegativeInt = is;
25
25
  const asNegativeInt = castType;
26
26
  const NegativeInt = {
27
27
  /**
28
- * Type guard to check if a value is a NegativeInt.
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 maximum value for a negative integer.
36
- *
37
- * @readonly
36
+ * The largest value representable as `NegativeInt`.
38
37
  */
39
38
  MAX_VALUE,
40
39
  /**
41
40
  * Returns the absolute value of a negative integer.
42
41
  *
43
- * @param a The negative integer.
44
- * @returns The absolute value as a PositiveInt.
42
+ * The result is non-negative and keeps the `NegativeInt` brand. Note that
43
+ * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
44
+ * use `SafeInt` for guaranteed precision.
45
+ *
46
+ * @param a - The negative integer value
47
+ * @returns The absolute value as a non-negative `NegativeInt`
45
48
  */
46
49
  abs,
47
50
  /**
48
- * Returns the smaller of two negative integers.
51
+ * Returns the smallest of the given negative integers.
49
52
  *
50
- * @param a The first negative integer.
51
- * @param b The second negative integer.
52
- * @returns The minimum value as a NegativeInt.
53
+ * @param values - The negative integers to compare (at least one required)
54
+ * @returns The smallest value as a `NegativeInt`
53
55
  */
54
56
  min: min_,
55
57
  /**
56
- * Returns the larger of two negative integers.
58
+ * Returns the largest of the given negative integers.
57
59
  *
58
- * @param a The first negative integer.
59
- * @param b The second negative integer.
60
- * @returns The maximum value as a NegativeInt.
60
+ * @param values - The negative integers to compare (at least one required)
61
+ * @returns The largest value as a `NegativeInt`
61
62
  */
62
63
  max: max_,
63
64
  /**
64
- * Clamps a number to the negative integer range.
65
+ * Clamps a `number` into the `NegativeInt` range, rounding to the nearest
66
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
65
67
  *
66
- * @param value The number to clamp.
67
- * @returns The value clamped to `[-∞, -1]` as a NegativeInt.
68
+ * @param value - The value to clamp
69
+ * @returns The clamped value as a `NegativeInt`
68
70
  */
69
71
  clamp,
70
72
  /**
71
- * Generates a random NegativeInt value within the valid range.
73
+ * Generates a random `NegativeInt` within the given range.
72
74
  *
73
- * @returns A random negative integer.
75
+ * The range is inclusive on both ends.
76
+ *
77
+ * @param min - The minimum value (inclusive)
78
+ * @param max - The maximum value (inclusive)
79
+ * @returns A random `NegativeInt` in `[min, max]`
74
80
  */
75
81
  random,
76
82
  /**
77
- * Raises a negative integer to the power of another negative integer.
83
+ * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored
84
+ * to an integer).
78
85
  *
79
- * @param a The base negative integer.
80
- * @param b The exponent negative integer.
81
- * @returns `a ** b` clamped to the negative integer range.
86
+ * @param a - The base negative integer
87
+ * @param b - The exponent negative integer
88
+ * @returns `a ** b` as a `NegativeInt`
82
89
  */
83
90
  pow,
84
91
  /**
85
- * Adds two negative integers.
92
+ * Adds two negative integers, returning `a + b` as a `NegativeInt`.
86
93
  *
87
- * @param a The first negative integer.
88
- * @param b The second negative integer.
89
- * @returns `a + b` as a NegativeInt.
94
+ * @param a - The first negative integer
95
+ * @param b - The second negative integer
96
+ * @returns The sum of `a` and `b` as a `NegativeInt`
90
97
  */
91
98
  add,
92
99
  /**
93
- * Subtracts one negative integer from another.
94
- *
95
- * The mathematical result can be positive, so it is clamped to the negative
96
- * integer range (maximum `-1`).
100
+ * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.
97
101
  *
98
- * @param a The minuend negative integer.
99
- * @param b The subtrahend negative integer.
100
- * @returns `a - b` clamped to the negative integer range.
102
+ * @param a - The first negative integer
103
+ * @param b - The second negative integer
104
+ * @returns The difference of `a` and `b` as a `NegativeInt`
101
105
  */
102
106
  sub
103
107
  };
@@ -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 clamp,\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\n/**\n * Returns the absolute value of a negative integer.\n *\n * The absolute value of a negative integer is always a positive integer\n * (`>= 1`), so the result is typed as a {@link PositiveInt}.\n *\n * @param x - The negative integer.\n * @returns `|x|` as a PositiveInt.\n */\nconst abs = (x: WithSmallInt<ElementType>): PositiveInt =>\n PositiveInt.clamp(Math.abs(x));\n\n/**\n * Checks if a number is a NegativeInt (a negative integer `<= -1`).\n *\n * @param value The value to check.\n * @returns `true` if the value is a NegativeInt, `false` otherwise.\n */\nexport const isNegativeInt = is;\n\n/**\n * Casts a number to a NegativeInt type.\n *\n * @param value The value to cast.\n * @returns The value as a NegativeInt type.\n * @throws {TypeError} If the value is not a negative integer.\n */\nexport const asNegativeInt = castType;\n\n/**\n * Namespace providing type-safe arithmetic operations for negative integers.\n *\n * NegativeInt represents integers that are strictly less than zero (`<= -1`).\n * Operations that stay within the negative integers (such as `add`) clamp their\n * results to the valid range, while operations whose result leaves the set\n * (`mul`, `div`, `abs`) are typed to reflect the actual sign of the result.\n */\nexport const NegativeInt = {\n /**\n * Type guard to check if a value is a NegativeInt.\n *\n * @param value The value to check.\n * @returns `true` if the value is a negative integer, `false` otherwise.\n */\n is,\n\n /**\n * The maximum value for a negative integer.\n *\n * @readonly\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative integer.\n *\n * @param a The negative integer.\n * @returns The absolute value as a PositiveInt.\n */\n abs,\n\n /**\n * Returns the smaller of two negative integers.\n *\n * @param a The first negative integer.\n * @param b The second negative integer.\n * @returns The minimum value as a NegativeInt.\n */\n min: min_,\n\n /**\n * Returns the larger of two negative integers.\n *\n * @param a The first negative integer.\n * @param b The second negative integer.\n * @returns The maximum value as a NegativeInt.\n */\n max: max_,\n\n /**\n * Clamps a number to the negative integer range.\n *\n * @param value The number to clamp.\n * @returns The value clamped to `[-∞, -1]` as a NegativeInt.\n */\n clamp,\n\n /**\n * Generates a random NegativeInt value within the valid range.\n *\n * @returns A random negative integer.\n */\n random,\n\n /**\n * Raises a negative integer to the power of another negative integer.\n *\n * @param a The base negative integer.\n * @param b The exponent negative integer.\n * @returns `a ** b` clamped to the negative integer range.\n */\n pow,\n\n /**\n * Adds two negative integers.\n *\n * @param a The first negative integer.\n * @param b The second negative integer.\n * @returns `a + b` as a NegativeInt.\n */\n add,\n\n /**\n * Subtracts one negative integer from another.\n *\n * The mathematical result can be positive, so it is clamped to the negative\n * integer range (maximum `-1`).\n *\n * @param a The minuend negative integer.\n * @param b The subtrahend negative integer.\n * @returns `a - b` clamped to the negative integer range.\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,KAAA;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;AAWV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,WAAA,CAAY,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAQxB,MAAM,aAAA,GAAgB;AAStB,MAAM,aAAA,GAAgB;AAUtB,MAAM,WAAA,GAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AACF;;;;"}
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 clamp,\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.clamp(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`.\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 * Clamps a `number` into the `NegativeInt` range, rounding to the nearest\n * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NegativeInt`\n */\n clamp,\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,KAAA;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,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAWxB,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,EAKA,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,EASL,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,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA;AACF;;;;"}