Scoop API

scoop:scoop.core:0.1.0

src/integer_ulong.scoop

Selected production source · src/integer_ulong.scoop

1/**
2 * A 64-bit unsigned integer. Arithmetic wraps modulo 2^64; division by zero throws
3 * [ArithmeticException]. Conversions are explicit and preserve the language's fixed-width rules on
4 * every target.
5 */
6@Intrinsic("core_ulong")
7public struct ULong :
8 Add<ULong, ULong>,
9 Sub<ULong, ULong>,
10 Mul<ULong, ULong>,
11 Div<ULong, ULong>,
12 Rem<ULong, ULong>,
13 UnaryPlus<ULong>,
14 UnaryMinus<ULong>,
15 Increment<ULong>,
16 Decrement<ULong>,
17 Compare<ULong>,
18 RangeTo<ULong, ULongRange>,
19 RangeUntil<ULong, ULongRange>,
20 Equals<ULong>, ToString, Hash {
21 /**
22 * Rounds the integer directly to IEEE binary32 using round-to-nearest, ties-to-even.
23 */
24 @NoGC @Intrinsic("ulong_to_float")
25 public fun toFloat(): Float
27 /**
28 * Rounds the integer directly to IEEE binary64 using round-to-nearest, ties-to-even.
29 */
30 @NoGC @Intrinsic("ulong_to_double")
31 public fun toDouble(): Double
33 /**
34 * Compares the mathematical values of two integers of the same type.
35 */
36 @NoGC
37 @Intrinsic("ulong_equals")
38 public override operator fun equals(other: ULong): Boolean
41 /**
42 * Returns the unchanged integer value.
43 */
44 @NoGC
45 @Intrinsic("ulong_unary_plus")
46 public override operator fun unaryPlus(): ULong
48 /**
49 * Returns the additive inverse modulo 2^64, including at the representation boundary.
50 */
51 @NoGC
52 @Intrinsic("ulong_unary_minus")
53 public override operator fun unaryMinus(): ULong
55 /**
56 * Returns the value plus one, wrapping modulo 2^64.
57 */
58 @NoGC
59 @Intrinsic("ulong_inc")
60 public override operator fun inc(): ULong
62 /**
63 * Returns the value minus one, wrapping modulo 2^64.
64 */
65 @NoGC
66 @Intrinsic("ulong_dec")
67 public override operator fun dec(): ULong
69 /**
70 * Returns the sum modulo 2^64; overflow does not throw.
71 */
72 @NoGC
73 @Intrinsic("ulong_add")
74 public override operator fun plus(other: ULong): ULong
76 /**
77 * Returns the difference modulo 2^64; overflow does not throw.
78 */
79 @NoGC
80 @Intrinsic("ulong_sub")
81 public override operator fun minus(other: ULong): ULong
83 /**
84 * Returns the product modulo 2^64; overflow does not throw.
85 */
86 @NoGC
87 @Intrinsic("ulong_mul")
88 public override operator fun times(other: ULong): ULong
90 /**
91 * Returns the quotient truncated toward zero. A zero divisor throws [ArithmeticException].
92 */
93 @Intrinsic("ulong_div")
94 public override operator fun div(other: ULong): ULong
96 /**
97 * Returns the remainder associated with division truncated toward zero. A zero divisor throws
98 * [ArithmeticException].
99 */
100 @Intrinsic("ulong_rem")
101 public override operator fun rem(other: ULong): ULong
103 /**
104 * Returns -1, 0, or 1 using unsigned mathematical ordering.
105 */
106 @NoGC
107 @Intrinsic("ulong_compare_to")
108 public override operator fun compareTo(other: ULong): Long
110 /**
111 * Returns the bitwise intersection of the 64-bit operands.
112 */
113 @NoGC
114 @Intrinsic("ulong_and")
115 public infix fun and(other: ULong): ULong
117 /**
118 * Returns the bitwise union of the 64-bit operands.
119 */
120 @NoGC
121 @Intrinsic("ulong_or")
122 public infix fun or(other: ULong): ULong
124 /**
125 * Sets each result bit where the corresponding 64-bit operand bits differ.
126 */
127 @NoGC
128 @Intrinsic("ulong_xor")
129 public infix fun xor(other: ULong): ULong
131 /**
132 * Flips all 64 bits of the representation.
133 */
134 @NoGC
135 @Intrinsic("ulong_inv")
136 public fun inv(): ULong
138 /**
139 * Shifts left using the low 6 bits of the Long count; shifted-out bits are discarded.
140 */
141 @NoGC
142 @Intrinsic("ulong_shl")
143 public infix fun shl(count: Long): ULong
145 /**
146 * Shifts right using the low 6 bits of the Long count, filling with zero bits.
147 */
148 @NoGC
149 @Intrinsic("ulong_shr")
150 public infix fun shr(count: Long): ULong
152 /**
153 * Converts modulo 2^8 and interprets the result as a 8-bit signed integer. The conversion
154 * always succeeds.
155 */
156 @NoGC
157 @Intrinsic("ulong_to_int8")
158 public fun toByte(): Byte
160 /**
161 * Converts modulo 2^16 and interprets the result as a 16-bit signed integer. The conversion
162 * always succeeds.
163 */
164 @NoGC
165 @Intrinsic("ulong_to_int16")
166 public fun toShort(): Short
168 /**
169 * Converts modulo 2^32 and interprets the result as a 32-bit signed integer. The conversion
170 * always succeeds.
171 */
172 @NoGC
173 @Intrinsic("ulong_to_int")
174 public fun toInt(): Int
176 /**
177 * Converts modulo 2^64 and interprets the result as a 64-bit signed integer. The conversion
178 * always succeeds.
179 */
180 @NoGC
181 @Intrinsic("ulong_to_long")
182 public fun toLong(): Long
184 /**
185 * Converts modulo 2^8 and interprets the result as a 8-bit unsigned integer. The conversion
186 * always succeeds.
187 */
188 @NoGC
189 @Intrinsic("ulong_to_uint8")
190 public fun toUByte(): UByte
192 /**
193 * Converts modulo 2^16 and interprets the result as a 16-bit unsigned integer. The conversion
194 * always succeeds.
195 */
196 @NoGC
197 @Intrinsic("ulong_to_uint16")
198 public fun toUShort(): UShort
200 /**
201 * Converts modulo 2^32 and interprets the result as a 32-bit unsigned integer. The conversion
202 * always succeeds.
203 */
204 @NoGC
205 @Intrinsic("ulong_to_uint")
206 public fun toUInt(): UInt
208 /**
209 * Converts modulo 2^64 and interprets the result as a 64-bit unsigned integer. The conversion
210 * always succeeds.
211 */
212 @NoGC
213 @Intrinsic("ulong_to_ulong")
214 public fun toULong(): ULong
216 /**
217 * Creates an ascending range including both this value and the endpoint.
218 */
219 public override operator fun rangeTo(endpoint: ULong): ULongRange =
220 ULongRange(this, endpoint, 1uL, false, true)
222 /**
223 * Creates an ascending range including this value and excluding the endpoint.
224 */
225 public override operator fun rangeUntil(endpoint: ULong): ULongRange =
226 ULongRange(this, endpoint, 1uL, false, false)
228 /**
229 * Creates an ascending range with an exclusive endpoint.
230 */
231 public infix fun until(endpoint: ULong): ULongRange =
232 ULongRange(this, endpoint, 1uL, false, false)
234 /**
235 * Creates a descending range including both endpoints.
236 */
237 public infix fun downTo(endpoint: ULong): ULongRange =
238 ULongRange(this, endpoint, 1uL, true, true)
240 /**
241 * Returns the locale-independent decimal representation of this integer.
242 */
243 public override fun toString(): String = coreULongToString(this)
245 /**
246 * Returns a hash consistent with same-type integer equality.
247 */
248 public override fun hash(): Long = coreULongHash(this)
250 /**
251 * Fixed representation bounds and the scalar encoding, decoding, and inspection protocols.
252 */
253 public companion object : ValueEncoder<ULong>, ValueDecoder<ULong>, ValueInspector<ULong> {
254 /**
255 * Exposes the integer as a scalar value observation without reference identity.
256 */
257 public override fun inspect(value: ULong): ValueView =
258 ValueObservation(typeInfo<ULong>().type, None, { ValueShape.Scalar(ScalarValue.Unsigned(value)) })
260 /**
261 * The smallest representable 64-bit unsigned integer.
262 */
263 public const val MIN_VALUE: ULong = 0uL
264 /**
265 * The largest representable 64-bit unsigned integer.
266 */
267 public const val MAX_VALUE: ULong = 18446744073709551615uL
269 /**
270 * Writes the integer through the encoder's single-value container.
271 */
272 public override fun encode(value: ULong, encoder: Encoder): Unit =
273 encoder.singleValue().writeULong(value.toULong())
275 /**
276 * Decodes an integer and rejects values outside the 64-bit unsigned range with
277 * [DecodingException].
278 */
279 public override fun decode(decoder: Decoder): ULong =
280 decoder.singleValue().readULong()
281 }