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.
Files changed (185) hide show
  1. package/README.md +2 -2
  2. package/dist/number/branded-types/finite-number.d.mts +47 -61
  3. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  4. package/dist/number/branded-types/finite-number.mjs +37 -41
  5. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  6. package/dist/number/branded-types/int.d.mts +40 -46
  7. package/dist/number/branded-types/int.d.mts.map +1 -1
  8. package/dist/number/branded-types/int.mjs +29 -31
  9. package/dist/number/branded-types/int.mjs.map +1 -1
  10. package/dist/number/branded-types/int16.d.mts +71 -59
  11. package/dist/number/branded-types/int16.d.mts.map +1 -1
  12. package/dist/number/branded-types/int16.mjs +56 -47
  13. package/dist/number/branded-types/int16.mjs.map +1 -1
  14. package/dist/number/branded-types/int32.d.mts +71 -59
  15. package/dist/number/branded-types/int32.d.mts.map +1 -1
  16. package/dist/number/branded-types/int32.mjs +56 -47
  17. package/dist/number/branded-types/int32.mjs.map +1 -1
  18. package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
  19. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  20. package/dist/number/branded-types/negative-finite-number.mjs +62 -49
  21. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  22. package/dist/number/branded-types/negative-int.d.mts +66 -49
  23. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  24. package/dist/number/branded-types/negative-int.mjs +48 -39
  25. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  26. package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
  27. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  28. package/dist/number/branded-types/negative-safe-int.mjs +49 -44
  29. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  30. package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
  31. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  32. package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
  33. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  34. package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
  35. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  36. package/dist/number/branded-types/non-negative-int16.mjs +55 -45
  37. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  38. package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
  39. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  40. package/dist/number/branded-types/non-negative-int32.mjs +55 -46
  41. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  42. package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
  43. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  44. package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
  45. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  46. package/dist/number/branded-types/non-positive-int.d.mts +46 -146
  47. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  48. package/dist/number/branded-types/non-positive-int.mjs +33 -108
  49. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  50. package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
  51. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  52. package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
  53. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  54. package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
  55. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  56. package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
  57. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  58. package/dist/number/branded-types/non-zero-int.d.mts +51 -38
  59. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  60. package/dist/number/branded-types/non-zero-int.mjs +31 -27
  61. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  62. package/dist/number/branded-types/non-zero-int16.d.mts +59 -54
  63. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  64. package/dist/number/branded-types/non-zero-int16.mjs +44 -41
  65. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  66. package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
  67. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  68. package/dist/number/branded-types/non-zero-int32.mjs +44 -42
  69. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  70. package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
  71. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  72. package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
  73. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  74. package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
  75. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  76. package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
  77. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  78. package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
  79. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  80. package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
  81. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  82. package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
  83. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  84. package/dist/number/branded-types/positive-finite-number.mjs +67 -52
  85. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  86. package/dist/number/branded-types/positive-int.d.mts +53 -70
  87. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  88. package/dist/number/branded-types/positive-int.mjs +42 -52
  89. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  90. package/dist/number/branded-types/positive-int16.d.mts +68 -58
  91. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  92. package/dist/number/branded-types/positive-int16.mjs +52 -45
  93. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  94. package/dist/number/branded-types/positive-int32.d.mts +68 -58
  95. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  96. package/dist/number/branded-types/positive-int32.mjs +52 -45
  97. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  98. package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
  99. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  100. package/dist/number/branded-types/positive-safe-int.mjs +56 -48
  101. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  102. package/dist/number/branded-types/positive-uint16.d.mts +68 -58
  103. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  104. package/dist/number/branded-types/positive-uint16.mjs +52 -45
  105. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  106. package/dist/number/branded-types/positive-uint32.d.mts +68 -59
  107. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  108. package/dist/number/branded-types/positive-uint32.mjs +52 -46
  109. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  110. package/dist/number/branded-types/safe-int.d.mts +52 -66
  111. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  112. package/dist/number/branded-types/safe-int.mjs +45 -47
  113. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  114. package/dist/number/branded-types/safe-uint.d.mts +68 -58
  115. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  116. package/dist/number/branded-types/safe-uint.mjs +53 -46
  117. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  118. package/dist/number/branded-types/uint.d.mts +72 -55
  119. package/dist/number/branded-types/uint.d.mts.map +1 -1
  120. package/dist/number/branded-types/uint.mjs +52 -45
  121. package/dist/number/branded-types/uint.mjs.map +1 -1
  122. package/dist/number/branded-types/uint16.d.mts +66 -59
  123. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  124. package/dist/number/branded-types/uint16.mjs +51 -45
  125. package/dist/number/branded-types/uint16.mjs.map +1 -1
  126. package/dist/number/branded-types/uint32.d.mts +66 -57
  127. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  128. package/dist/number/branded-types/uint32.mjs +50 -45
  129. package/dist/number/branded-types/uint32.mjs.map +1 -1
  130. package/dist/number/enum/int8.d.mts +62 -66
  131. package/dist/number/enum/int8.d.mts.map +1 -1
  132. package/dist/number/enum/int8.mjs +57 -51
  133. package/dist/number/enum/int8.mjs.map +1 -1
  134. package/dist/number/enum/uint8.d.mts +66 -59
  135. package/dist/number/enum/uint8.d.mts.map +1 -1
  136. package/dist/number/enum/uint8.mjs +57 -51
  137. package/dist/number/enum/uint8.mjs.map +1 -1
  138. package/dist/number/refined-number-utils.d.mts +9 -9
  139. package/dist/number/refined-number-utils.d.mts.map +1 -1
  140. package/dist/number/refined-number-utils.mjs +7 -7
  141. package/dist/number/refined-number-utils.mjs.map +1 -1
  142. package/package.json +2 -1
  143. package/src/number/branded-types/finite-number.mts +47 -61
  144. package/src/number/branded-types/int.mts +40 -46
  145. package/src/number/branded-types/int16.mts +72 -60
  146. package/src/number/branded-types/int32.mts +72 -60
  147. package/src/number/branded-types/negative-finite-number.mts +78 -71
  148. package/src/number/branded-types/negative-finite-number.test.mts +4 -4
  149. package/src/number/branded-types/negative-int.mts +68 -60
  150. package/src/number/branded-types/negative-int.test.mts +5 -5
  151. package/src/number/branded-types/negative-safe-int.mts +66 -68
  152. package/src/number/branded-types/negative-safe-int.test.mts +4 -4
  153. package/src/number/branded-types/non-negative-finite-number.mts +81 -66
  154. package/src/number/branded-types/non-negative-int16.mts +72 -59
  155. package/src/number/branded-types/non-negative-int32.mts +72 -60
  156. package/src/number/branded-types/non-positive-finite-number.mts +71 -56
  157. package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
  158. package/src/number/branded-types/non-positive-int.mts +47 -147
  159. package/src/number/branded-types/non-positive-int.test.mts +7 -7
  160. package/src/number/branded-types/non-positive-safe-int.mts +63 -55
  161. package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
  162. package/src/number/branded-types/non-zero-finite-number.mts +62 -51
  163. package/src/number/branded-types/non-zero-int.mts +51 -38
  164. package/src/number/branded-types/non-zero-int16.mts +60 -55
  165. package/src/number/branded-types/non-zero-int32.mts +60 -56
  166. package/src/number/branded-types/non-zero-safe-int.mts +61 -56
  167. package/src/number/branded-types/non-zero-uint16.mts +60 -55
  168. package/src/number/branded-types/non-zero-uint32.mts +60 -55
  169. package/src/number/branded-types/positive-finite-number.mts +83 -65
  170. package/src/number/branded-types/positive-int.mts +54 -71
  171. package/src/number/branded-types/positive-int16.mts +69 -59
  172. package/src/number/branded-types/positive-int32.mts +69 -59
  173. package/src/number/branded-types/positive-safe-int.mts +73 -62
  174. package/src/number/branded-types/positive-uint16.mts +69 -59
  175. package/src/number/branded-types/positive-uint32.mts +69 -60
  176. package/src/number/branded-types/safe-int.mts +53 -67
  177. package/src/number/branded-types/safe-uint.mts +69 -59
  178. package/src/number/branded-types/uint.mts +73 -56
  179. package/src/number/branded-types/uint16.mts +67 -60
  180. package/src/number/branded-types/uint32.mts +67 -58
  181. package/src/number/enum/int8.mts +70 -73
  182. package/src/number/enum/int8.test.mts +7 -4
  183. package/src/number/enum/uint8.mts +74 -66
  184. package/src/number/enum/uint8.test.mts +7 -4
  185. package/src/number/refined-number-utils.mts +22 -19
@@ -6,8 +6,8 @@ const {
6
6
  MIN_VALUE,
7
7
  add,
8
8
  castType,
9
- clamp,
10
9
  div,
10
+ fromNumber,
11
11
  is,
12
12
  max: max_,
13
13
  min: min_,
@@ -25,93 +25,98 @@ const isUint32 = is;
25
25
  const asUint32 = castType;
26
26
  const Uint32 = {
27
27
  /**
28
- * Type guard that checks if a value is a 32-bit unsigned integer.
28
+ * Type guard that checks if a value is a non-negative integer less than 2^32.
29
29
  *
30
30
  * @param value - The value to check
31
- * @returns `true` if the value is within the range [0, 2^32), `false`
32
- * otherwise
31
+ * @returns `true` if the value is a non-negative integer less than 2^32, `false` otherwise
32
+ * @see {@link isUint32} for usage examples
33
33
  */
34
34
  is,
35
35
  /**
36
- * The minimum value for a Uint32.
37
- *
38
- * @readonly
36
+ * The smallest value representable as `Uint32` (the lower saturation target
37
+ * of `fromNumber`).
39
38
  */
40
39
  MIN_VALUE,
41
40
  /**
42
- * The maximum value for a Uint32.
43
- *
44
- * @readonly
41
+ * The largest value representable as `Uint32` (the upper saturation target of
42
+ * `fromNumber`).
45
43
  */
46
44
  MAX_VALUE,
47
45
  /**
48
- * Returns the minimum of multiple Uint32 values.
46
+ * Returns the smallest of the given non-negative integers.
49
47
  *
50
- * @param values - The Uint32 values to compare
51
- * @returns The smallest value as a Uint32
48
+ * @param values - The non-negative integers to compare (at least one required)
49
+ * @returns The smallest value as an `Uint32`
52
50
  */
53
51
  min: min_,
54
52
  /**
55
- * Returns the maximum of multiple Uint32 values.
53
+ * Returns the largest of the given non-negative integers.
56
54
  *
57
- * @param values - The Uint32 values to compare
58
- * @returns The largest value as a Uint32
55
+ * @param values - The non-negative integers to compare (at least one required)
56
+ * @returns The largest value as an `Uint32`
59
57
  */
60
58
  max: max_,
61
59
  /**
62
- * Clamps a Uint32 to be within the specified range.
60
+ * Converts an arbitrary `number` into an `Uint32`, rounding to the nearest
61
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
63
62
  *
64
- * @param value - The value to clamp
65
- * @param min - The minimum value
66
- * @param max - The maximum value
67
- * @returns The clamped value as a Uint32
63
+ * Unlike `asUint32`, this is total: out-of-range inputs are clamped to the
64
+ * nearest representable `Uint32` instead of throwing.
65
+ *
66
+ * @param value - The value to convert
67
+ * @returns The value as an `Uint32`
68
68
  */
69
- clamp,
69
+ fromNumber,
70
70
  /**
71
- * Generates a random Uint32 value.
71
+ * Generates a random `Uint32` within the given range.
72
+ *
73
+ * The range is inclusive on both ends.
72
74
  *
73
- * @returns A random Uint32 value within [0, 2^32)
75
+ * @param min - The minimum value (inclusive)
76
+ * @param max - The maximum value (inclusive)
77
+ * @returns A random `Uint32` in `[min, max]`
74
78
  */
75
79
  random,
76
80
  /**
77
- * Raises a Uint32 to a power, with result clamped to [0, 2^32).
81
+ * Raises `a` to the power `b`, returning `a ** b` as an `Uint32` (floored to
82
+ * an integer).
78
83
  *
79
- * @param a - The base Uint32
80
- * @param b - The exponent Uint32
81
- * @returns `a ** b` as a Uint32, clamped to valid range
84
+ * @param a - The base non-negative integer
85
+ * @param b - The exponent non-negative integer
86
+ * @returns `a ** b` as an `Uint32`
82
87
  */
83
88
  pow,
84
89
  /**
85
- * Adds two Uint32 values, with result clamped to [0, 2^32).
90
+ * Adds two non-negative integers, returning `a + b` as an `Uint32`.
86
91
  *
87
- * @param a - First Uint32
88
- * @param b - Second Uint32
89
- * @returns `a + b` as a Uint32, clamped to valid range
92
+ * @param a - The first non-negative integer
93
+ * @param b - The second non-negative integer
94
+ * @returns The sum of `a` and `b` as an `Uint32`
90
95
  */
91
96
  add,
92
97
  /**
93
- * Subtracts two Uint32 values, with result clamped to [0, 2^32).
98
+ * Subtracts two non-negative integers, returning `a - b` as an `Uint32`.
94
99
  *
95
- * @param a - First Uint32
96
- * @param b - Second Uint32
97
- * @returns `a - b` as a Uint32, clamped to valid range (minimum 0)
100
+ * @param a - The first non-negative integer
101
+ * @param b - The second non-negative integer
102
+ * @returns The difference of `a` and `b` as an `Uint32`
98
103
  */
99
104
  sub,
100
105
  /**
101
- * Multiplies two Uint32 values, with result clamped to [0, 2^32).
106
+ * Multiplies two non-negative integers, returning `a * b` as an `Uint32`.
102
107
  *
103
- * @param a - First Uint32
104
- * @param b - Second Uint32
105
- * @returns `a * b` as a Uint32, clamped to valid range
108
+ * @param a - The first non-negative integer
109
+ * @param b - The second non-negative integer
110
+ * @returns The product of `a` and `b` as an `Uint32`
106
111
  */
107
112
  mul,
108
113
  /**
109
- * Divides two Uint32 values using floor division, with result clamped to [0,
110
- * 2^32).
114
+ * Divides two non-negative integers using floor division (`⌊a / b⌋`): the
115
+ * result is `a / b` rounded toward negative infinity, as an `Uint32`.
111
116
  *
112
- * @param a - The dividend Uint32
113
- * @param b - The divisor Uint32
114
- * @returns `⌊a / b⌋` as a Uint32, clamped to valid range
117
+ * @param a - The dividend
118
+ * @param b - The divisor (must be non-zero)
119
+ * @returns The floored quotient as an `Uint32`
115
120
  */
116
121
  div
117
122
  };
@@ -1 +1 @@
1
- {"version":3,"file":"uint32.mjs","sources":["../../../src/number/branded-types/uint32.mts"],"sourcesContent":["import { type Uint32 as TtfImported_Uint32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint32 = TtfImported_Uint32;\n\ntype ElementType = Uint32;\n\nconst typeNameInMessage = 'a non-negative integer less than 2^32';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 0,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 0,\n MAX_VALUE: 2 ** 32 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Checks if a number is a Uint32 (32-bit unsigned integer in the range [0,\n * 2^32)).\n *\n * @param value The value to check.\n * @returns `true` if the value is a Uint32, `false` otherwise.\n */\nexport const isUint32 = is;\n\n/**\n * Casts a number to a Uint32 type.\n *\n * @param value The value to cast.\n * @returns The value as a Uint32 type.\n * @throws {TypeError} If the value is not a non-negative integer less than\n * 2^32.\n */\nexport const asUint32 = castType;\n\n/**\n * Utility functions for working with Uint32 (32-bit unsigned integer) branded\n * types. Provides type-safe operations that ensure results remain within the\n * valid range [0, 2^32). All arithmetic operations are clamped to maintain the\n * Uint32 constraint.\n */\nexport const Uint32 = {\n /**\n * Type guard that checks if a value is a 32-bit unsigned integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is within the range [0, 2^32), `false`\n * otherwise\n */\n is,\n\n /**\n * The minimum value for a Uint32.\n *\n * @readonly\n */\n MIN_VALUE,\n\n /**\n * The maximum value for a Uint32.\n *\n * @readonly\n */\n MAX_VALUE,\n\n /**\n * Returns the minimum of multiple Uint32 values.\n *\n * @param values - The Uint32 values to compare\n * @returns The smallest value as a Uint32\n */\n min: min_,\n\n /**\n * Returns the maximum of multiple Uint32 values.\n *\n * @param values - The Uint32 values to compare\n * @returns The largest value as a Uint32\n */\n max: max_,\n\n /**\n * Clamps a Uint32 to be within the specified range.\n *\n * @param value - The value to clamp\n * @param min - The minimum value\n * @param max - The maximum value\n * @returns The clamped value as a Uint32\n */\n clamp,\n\n /**\n * Generates a random Uint32 value.\n *\n * @returns A random Uint32 value within [0, 2^32)\n */\n random,\n\n /**\n * Raises a Uint32 to a power, with result clamped to [0, 2^32).\n *\n * @param a - The base Uint32\n * @param b - The exponent Uint32\n * @returns `a ** b` as a Uint32, clamped to valid range\n */\n pow,\n\n /**\n * Adds two Uint32 values, with result clamped to [0, 2^32).\n *\n * @param a - First Uint32\n * @param b - Second Uint32\n * @returns `a + b` as a Uint32, clamped to valid range\n */\n add,\n\n /**\n * Subtracts two Uint32 values, with result clamped to [0, 2^32).\n *\n * @param a - First Uint32\n * @param b - Second Uint32\n * @returns `a - b` as a Uint32, clamped to valid range (minimum 0)\n */\n sub,\n\n /**\n * Multiplies two Uint32 values, with result clamped to [0, 2^32).\n *\n * @param a - First Uint32\n * @param b - Second Uint32\n * @returns `a * b` as a Uint32, clamped to valid range\n */\n mul,\n\n /**\n * Divides two Uint32 values using floor division, with result clamped to [0,\n * 2^32).\n *\n * @param a - The dividend Uint32\n * @param b - The divisor Uint32\n * @returns `⌊a / b⌋` as a Uint32, clamped to valid range\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint32,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('=');\n\nexpectType<\n typeof Uint32,\n TsDataForgeInternals.Ref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AA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"uint32.mjs","sources":["../../../src/number/branded-types/uint32.mts"],"sourcesContent":["import { type Uint32 as TtfImported_Uint32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint32 = TtfImported_Uint32;\n\ntype ElementType = Uint32;\n\nconst typeNameInMessage = 'a non-negative integer less than 2^32';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 0,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 0,\n MAX_VALUE: 2 ** 32 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-negative integer less than 2^32.\n *\n * Returns `true` for a non-negative integer less than 2^32 — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer less than 2^32, `false` otherwise\n */\nexport const isUint32 = is;\n\n/**\n * Casts a `number` to the `Uint32` branded type.\n *\n * Validates that the value is a non-negative integer less than 2^32 and returns\n * it with the `Uint32` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Uint32`\n * @throws {TypeError} If the value is not a non-negative integer less than 2^32\n */\nexport const asUint32 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Uint32` branded type.\n *\n * The `Uint32` type represents a non-negative integer less than 2^32. Division\n * (`div`) uses floor division.\n */\nexport const Uint32 = {\n /**\n * Type guard that checks if a value is a non-negative integer less than 2^32.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer less than 2^32, `false` otherwise\n * @see {@link isUint32} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Uint32` (the lower saturation target\n * of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Uint32` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-negative integers.\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The smallest value as an `Uint32`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative integers.\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The largest value as an `Uint32`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Uint32`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asUint32`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Uint32` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Uint32`\n */\n fromNumber,\n\n /**\n * Generates a random `Uint32` 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 `Uint32` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Uint32` (floored to\n * an integer).\n *\n * @param a - The base non-negative integer\n * @param b - The exponent non-negative integer\n * @returns `a ** b` as an `Uint32`\n */\n pow,\n\n /**\n * Adds two non-negative integers, returning `a + b` as an `Uint32`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The sum of `a` and `b` as an `Uint32`\n */\n add,\n\n /**\n * Subtracts two non-negative integers, returning `a - b` as an `Uint32`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The difference of `a` and `b` as an `Uint32`\n */\n sub,\n\n /**\n * Multiplies two non-negative integers, returning `a * b` as an `Uint32`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The product of `a` and `b` as an `Uint32`\n */\n mul,\n\n /**\n * Divides two non-negative integers using floor division (`⌊a / b⌋`): the\n * result is `a / b` rounded toward negative infinity, as an `Uint32`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Uint32`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint32,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('=');\n\nexpectType<\n typeof Uint32,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,uCAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,QAAA,GAAW;AAYjB,MAAM,QAAA,GAAW;AAQjB,MAAM,MAAA,GAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;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,EAYL,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,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
@@ -1,139 +1,135 @@
1
1
  import { type AbsoluteValue, type Int8 as TtfImported_Int8 } from 'ts-type-forge';
2
2
  export type Int8 = TtfImported_Int8;
3
3
  /**
4
- * Type guard that checks if a value is an 8-bit signed integer.
4
+ * Type guard that checks if a value is an integer in [-128, 127].
5
5
  *
6
- * An Int8 is a signed integer in the range [-128, 127], representing values
7
- * that fit in exactly 8 bits of memory.
6
+ * Returns `true` for an integer in [-128, 127] — a value with no fractional
7
+ * component.
8
8
  *
9
9
  * @param value - The value to check
10
- * @returns `true` if the value is an Int8, `false` otherwise
10
+ * @returns `true` if the value is an integer in [-128, 127], `false` otherwise
11
11
  */
12
12
  export declare const isInt8: (x: number) => x is Int8;
13
13
  /**
14
- * Casts a number to an Int8 branded type.
14
+ * Casts a `number` to the `Int8` branded type.
15
15
  *
16
- * This function validates that the input is within the Int8 range [-128, 127]
17
- * and is an integer, then returns it with the Int8 brand.
16
+ * Validates that the value is an integer in [-128, 127] and returns it with the
17
+ * `Int8` brand. Throws a `TypeError` otherwise.
18
18
  *
19
19
  * @param value - The value to cast
20
- * @returns The value as an Int8 branded type
21
- * @throws {TypeError} If the value is not a valid 8-bit signed integer
20
+ * @returns The value as an `Int8`
21
+ * @throws {TypeError} If the value is not an integer in [-128, 127]
22
22
  */
23
23
  export declare const asInt8: (x: number) => Int8;
24
24
  /**
25
- * Namespace providing type-safe operations for Int8 (8-bit signed integer)
26
- * branded types.
25
+ * Namespace providing type-safe operations for the `Int8` branded type.
27
26
  *
28
- * Int8 represents signed integers in the range [-128, 127], equivalent to a
29
- * signed byte in many programming languages. All operations automatically clamp
30
- * results to stay within this range, preventing overflow/underflow issues.
31
- *
32
- * This type is useful for:
33
- *
34
- * - Binary data processing (signed bytes)
35
- * - Small integer values with known bounds
36
- * - Embedded systems programming
37
- * - Memory-efficient integer storage
38
- * - Image processing (signed pixel offsets)
27
+ * The `Int8` type represents an integer in [-128, 127]. Division (`div`) uses
28
+ * floor division.
39
29
  */
40
30
  export declare const Int8: {
41
31
  /**
42
- * Type guard that checks if a value is an 8-bit signed integer.
32
+ * Type guard that checks if a value is an integer in [-128, 127].
43
33
  *
44
34
  * @param value - The value to check
45
- * @returns `true` if the value is in range [-128, 127] and is an integer
35
+ * @returns `true` if the value is an integer in [-128, 127], `false` otherwise
46
36
  * @see {@link isInt8} for usage examples
47
37
  */
48
38
  readonly is: (x: number) => x is Int8;
49
39
  /**
50
- * The minimum value for an 8-bit signed integer.
51
- *
52
- * @readonly
40
+ * The smallest value representable as `Int8` (the lower saturation target of
41
+ * `fromNumber`).
53
42
  */
54
43
  readonly MIN_VALUE: -128;
55
44
  /**
56
- * The maximum value for an 8-bit signed integer.
57
- *
58
- * @readonly
45
+ * The largest value representable as `Int8` (the upper saturation target of
46
+ * `fromNumber`).
59
47
  */
60
48
  readonly MAX_VALUE: 127;
61
49
  /**
62
- * Returns the minimum value from a list of Int8 values.
50
+ * Returns the smallest of the given integers.
63
51
  *
64
- * @param values - The Int8 values to compare (at least one required)
65
- * @returns The smallest value as an Int8
52
+ * @param values - The integers to compare (at least one required)
53
+ * @returns The smallest value as an `Int8`
66
54
  */
67
55
  readonly min: (...values: readonly Int8[]) => Int8;
68
56
  /**
69
- * Returns the maximum value from a list of Int8 values.
57
+ * Returns the largest of the given integers.
70
58
  *
71
- * @param values - The Int8 values to compare (at least one required)
72
- * @returns The largest value as an Int8
59
+ * @param values - The integers to compare (at least one required)
60
+ * @returns The largest value as an `Int8`
73
61
  */
74
62
  readonly max: (...values: readonly Int8[]) => Int8;
75
63
  /**
76
- * Clamps a number to the Int8 range.
64
+ * Converts an arbitrary `number` into an `Int8`, rounding to the nearest
65
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
66
+ *
67
+ * Unlike `asInt8`, this is total: out-of-range inputs are clamped to the
68
+ * nearest representable `Int8` instead of throwing.
77
69
  *
78
- * @param value The number to clamp.
79
- * @returns The value clamped to [-128, 127] as an Int8.
70
+ * @param value - The value to convert
71
+ * @returns The value as an `Int8`
80
72
  */
81
- readonly clamp: (a: number) => Int8;
73
+ readonly fromNumber: (a: number) => Int8;
82
74
  /**
83
- * Returns the absolute value of an Int8.
75
+ * Returns the absolute value of an integer in [-128, 127].
76
+ *
77
+ * The result is non-negative and keeps the `Int8` brand.
84
78
  *
85
- * @param value The Int8 value.
86
- * @returns The absolute value as an Int8, clamped to valid range.
79
+ * @param a - The integer value
80
+ * @returns The absolute value as a non-negative `Int8`
87
81
  */
88
82
  readonly abs: <N extends Int8>(x: N) => AbsoluteValue<N>;
89
83
  /**
90
- * Generates a random Int8 value within the specified range (inclusive).
84
+ * Generates a random `Int8` within the given range.
91
85
  *
92
- * Both bounds are inclusive. If min > max, they are automatically swapped.
86
+ * The range is inclusive on both ends.
93
87
  *
94
88
  * @param min - The minimum value (inclusive)
95
89
  * @param max - The maximum value (inclusive)
96
- * @returns A random Int8 in the range [min, max]
90
+ * @returns A random `Int8` in `[min, max]`
97
91
  */
98
92
  readonly random: (min: Int8, max: Int8) => Int8;
99
93
  /**
100
- * Raises x to the power of y, clamped to Int8 range.
94
+ * Raises `a` to the power `b`, returning `a ** b` as an `Int8` (floored to an
95
+ * integer).
101
96
  *
102
- * @param x - The base
103
- * @param y - The exponent
104
- * @returns `x ** y` clamped to [-128, 127]
97
+ * @param a - The base integer
98
+ * @param b - The exponent integer
99
+ * @returns `a ** b` as an `Int8`
105
100
  */
106
101
  readonly pow: (x: Int8, y: Int8) => Int8;
107
102
  /**
108
- * Adds two Int8 values, clamped to Int8 range.
103
+ * Adds two integers, returning `a + b` as an `Int8`.
109
104
  *
110
- * @param x - First operand
111
- * @param y - Second operand
112
- * @returns `x + y` clamped to [-128, 127]
105
+ * @param a - The first integer
106
+ * @param b - The second integer
107
+ * @returns The sum of `a` and `b` as an `Int8`
113
108
  */
114
109
  readonly add: (x: Int8, y: Int8) => Int8;
115
110
  /**
116
- * Subtracts two Int8 values, clamped to Int8 range.
111
+ * Subtracts two integers, returning `a - b` as an `Int8`.
117
112
  *
118
- * @param x - First operand
119
- * @param y - Second operand
120
- * @returns `x - y` clamped to [-128, 127]
113
+ * @param a - The first integer
114
+ * @param b - The second integer
115
+ * @returns The difference of `a` and `b` as an `Int8`
121
116
  */
122
117
  readonly sub: (x: Int8, y: Int8) => Int8;
123
118
  /**
124
- * Multiplies two Int8 values, clamped to Int8 range.
119
+ * Multiplies two integers, returning `a * b` as an `Int8`.
125
120
  *
126
- * @param x - First operand
127
- * @param y - Second operand
128
- * @returns `x * y` clamped to [-128, 127]
121
+ * @param a - The first integer
122
+ * @param b - The second integer
123
+ * @returns The product of `a` and `b` as an `Int8`
129
124
  */
130
125
  readonly mul: (x: Int8, y: Int8) => Int8;
131
126
  /**
132
- * Divides two Int8 values, clamped to Int8 range.
127
+ * Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
128
+ * b` rounded toward negative infinity, as an `Int8`.
133
129
  *
134
- * @param x - The dividend
135
- * @param y - The divisor (cannot be 0)
136
- * @returns `⌊x / y⌋` clamped to [-128, 127]
130
+ * @param a - The dividend
131
+ * @param b - The divisor (must be non-zero)
132
+ * @returns The floored quotient as an `Int8`
137
133
  */
138
134
  readonly div: (x: Int8, y: Exclude<Int8, 0>) => Int8;
139
135
  };
@@ -1 +1 @@
1
- {"version":3,"file":"int8.d.mts","sourceRoot":"","sources":["../../../src/number/enum/int8.mts"],"names":[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atorsForInteger({
@@ -19,118 +19,124 @@ const castType = (x) => (
19
19
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
20
20
  castTypeImpl(x)
21
21
  );
22
- const clamp = (a) => castType(clampImpl(a));
22
+ const fromNumber = (a) => castType(fromNumberImpl(a));
23
23
  const abs = (x) => (
24
24
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
25
25
  Math.abs(x)
26
26
  );
27
27
  const min_ = (...values) => castType(Math.min(...values));
28
28
  const max_ = (...values) => castType(Math.max(...values));
29
- const pow = (x, y) => clamp(x ** y);
30
- const add = (x, y) => clamp(x + y);
31
- const sub = (x, y) => clamp(x - y);
32
- const mul = (x, y) => clamp(x * y);
33
- const div = (x, y) => clamp(Math.floor(x / y));
29
+ const pow = (x, y) => fromNumber(x ** y);
30
+ const add = (x, y) => fromNumber(x + y);
31
+ const sub = (x, y) => fromNumber(x - y);
32
+ const mul = (x, y) => fromNumber(x * y);
33
+ const div = (x, y) => fromNumber(Math.floor(x / y));
34
34
  const random = (min, max) => castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));
35
35
  const isInt8 = is;
36
36
  const asInt8 = castType;
37
37
  const Int8 = {
38
38
  /**
39
- * Type guard that checks if a value is an 8-bit signed integer.
39
+ * Type guard that checks if a value is an integer in [-128, 127].
40
40
  *
41
41
  * @param value - The value to check
42
- * @returns `true` if the value is in range [-128, 127] and is an integer
42
+ * @returns `true` if the value is an integer in [-128, 127], `false` otherwise
43
43
  * @see {@link isInt8} for usage examples
44
44
  */
45
45
  is,
46
46
  /**
47
- * The minimum value for an 8-bit signed integer.
48
- *
49
- * @readonly
47
+ * The smallest value representable as `Int8` (the lower saturation target of
48
+ * `fromNumber`).
50
49
  */
51
50
  MIN_VALUE,
52
51
  /**
53
- * The maximum value for an 8-bit signed integer.
54
- *
55
- * @readonly
52
+ * The largest value representable as `Int8` (the upper saturation target of
53
+ * `fromNumber`).
56
54
  */
57
55
  MAX_VALUE,
58
56
  /**
59
- * Returns the minimum value from a list of Int8 values.
57
+ * Returns the smallest of the given integers.
60
58
  *
61
- * @param values - The Int8 values to compare (at least one required)
62
- * @returns The smallest value as an Int8
59
+ * @param values - The integers to compare (at least one required)
60
+ * @returns The smallest value as an `Int8`
63
61
  */
64
62
  min: min_,
65
63
  /**
66
- * Returns the maximum value from a list of Int8 values.
64
+ * Returns the largest of the given integers.
67
65
  *
68
- * @param values - The Int8 values to compare (at least one required)
69
- * @returns The largest value as an Int8
66
+ * @param values - The integers to compare (at least one required)
67
+ * @returns The largest value as an `Int8`
70
68
  */
71
69
  max: max_,
72
70
  /**
73
- * Clamps a number to the Int8 range.
71
+ * Converts an arbitrary `number` into an `Int8`, rounding to the nearest
72
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
74
73
  *
75
- * @param value The number to clamp.
76
- * @returns The value clamped to [-128, 127] as an Int8.
74
+ * Unlike `asInt8`, this is total: out-of-range inputs are clamped to the
75
+ * nearest representable `Int8` instead of throwing.
76
+ *
77
+ * @param value - The value to convert
78
+ * @returns The value as an `Int8`
77
79
  */
78
- clamp,
80
+ fromNumber,
79
81
  /**
80
- * Returns the absolute value of an Int8.
82
+ * Returns the absolute value of an integer in [-128, 127].
83
+ *
84
+ * The result is non-negative and keeps the `Int8` brand.
81
85
  *
82
- * @param value The Int8 value.
83
- * @returns The absolute value as an Int8, clamped to valid range.
86
+ * @param a - The integer value
87
+ * @returns The absolute value as a non-negative `Int8`
84
88
  */
85
89
  abs,
86
90
  /**
87
- * Generates a random Int8 value within the specified range (inclusive).
91
+ * Generates a random `Int8` within the given range.
88
92
  *
89
- * Both bounds are inclusive. If min > max, they are automatically swapped.
93
+ * The range is inclusive on both ends.
90
94
  *
91
95
  * @param min - The minimum value (inclusive)
92
96
  * @param max - The maximum value (inclusive)
93
- * @returns A random Int8 in the range [min, max]
97
+ * @returns A random `Int8` in `[min, max]`
94
98
  */
95
99
  random,
96
100
  /**
97
- * Raises x to the power of y, clamped to Int8 range.
101
+ * Raises `a` to the power `b`, returning `a ** b` as an `Int8` (floored to an
102
+ * integer).
98
103
  *
99
- * @param x - The base
100
- * @param y - The exponent
101
- * @returns `x ** y` clamped to [-128, 127]
104
+ * @param a - The base integer
105
+ * @param b - The exponent integer
106
+ * @returns `a ** b` as an `Int8`
102
107
  */
103
108
  pow,
104
109
  /**
105
- * Adds two Int8 values, clamped to Int8 range.
110
+ * Adds two integers, returning `a + b` as an `Int8`.
106
111
  *
107
- * @param x - First operand
108
- * @param y - Second operand
109
- * @returns `x + y` clamped to [-128, 127]
112
+ * @param a - The first integer
113
+ * @param b - The second integer
114
+ * @returns The sum of `a` and `b` as an `Int8`
110
115
  */
111
116
  add,
112
117
  /**
113
- * Subtracts two Int8 values, clamped to Int8 range.
118
+ * Subtracts two integers, returning `a - b` as an `Int8`.
114
119
  *
115
- * @param x - First operand
116
- * @param y - Second operand
117
- * @returns `x - y` clamped to [-128, 127]
120
+ * @param a - The first integer
121
+ * @param b - The second integer
122
+ * @returns The difference of `a` and `b` as an `Int8`
118
123
  */
119
124
  sub,
120
125
  /**
121
- * Multiplies two Int8 values, clamped to Int8 range.
126
+ * Multiplies two integers, returning `a * b` as an `Int8`.
122
127
  *
123
- * @param x - First operand
124
- * @param y - Second operand
125
- * @returns `x * y` clamped to [-128, 127]
128
+ * @param a - The first integer
129
+ * @param b - The second integer
130
+ * @returns The product of `a` and `b` as an `Int8`
126
131
  */
127
132
  mul,
128
133
  /**
129
- * Divides two Int8 values, clamped to Int8 range.
134
+ * Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
135
+ * b` rounded toward negative infinity, as an `Int8`.
130
136
  *
131
- * @param x - The dividend
132
- * @param y - The divisor (cannot be 0)
133
- * @returns `⌊x / y⌋` clamped to [-128, 127]
137
+ * @param a - The dividend
138
+ * @param b - The divisor (must be non-zero)
139
+ * @returns The floored quotient as an `Int8`
134
140
  */
135
141
  div
136
142
  };