Scoop API

scoop:scoop.core:0.1.0

src/integer_long.scoop

Selected production source · src/integer_long.scoop

1/**
2 * A 64-bit signed 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_long")
7public struct Long :
8 Add<Long, Long>,
9 Sub<Long, Long>,
10 Mul<Long, Long>,
11 Div<Long, Long>,
12 Rem<Long, Long>,
13 UnaryPlus<Long>,
14 UnaryMinus<Long>,
15 Increment<Long>,
16 Decrement<Long>,
17 Compare<Long>,
18 RangeTo<Long, LongRange>,
19 RangeUntil<Long, LongRange>,
20 Equals<Long>, ToString, Hash {
21 /**
22 * Rounds the integer directly to IEEE binary32 using round-to-nearest, ties-to-even.
23 */
24 @NoGC @Intrinsic("long_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("long_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("long_equals")
38 public override operator fun equals(other: Long): Boolean
41 /**
42 * Returns the unchanged integer value.
43 */
44 @NoGC
45 @Intrinsic("long_unary_plus")
46 public override operator fun unaryPlus(): Long
48 /**
49 * Returns the additive inverse modulo 2^64, including at the representation boundary.
50 */
51 @NoGC
52 @Intrinsic("long_unary_minus")
53 public override operator fun unaryMinus(): Long
55 /**
56 * Returns the value plus one, wrapping modulo 2^64.
57 */
58 @NoGC
59 @Intrinsic("long_inc")
60 public override operator fun inc(): Long
62 /**
63 * Returns the value minus one, wrapping modulo 2^64.
64 */
65 @NoGC
66 @Intrinsic("long_dec")
67 public override operator fun dec(): Long
69 /**
70 * Returns the sum modulo 2^64; overflow does not throw.
71 */
72 @NoGC
73 @Intrinsic("long_add")
74 public override operator fun plus(other: Long): Long
76 /**
77 * Returns the difference modulo 2^64; overflow does not throw.
78 */
79 @NoGC
80 @Intrinsic("long_sub")
81 public override operator fun minus(other: Long): Long
83 /**
84 * Returns the product modulo 2^64; overflow does not throw.
85 */
86 @NoGC
87 @Intrinsic("long_mul")
88 public override operator fun times(other: Long): Long
90 /**
91 * Returns the quotient truncated toward zero. A zero divisor throws [ArithmeticException]. The
92 * minimum value divided by -1 wraps to the minimum value.
93 */
94 @Intrinsic("long_div")
95 public override operator fun div(other: Long): Long
97 /**
98 * Returns the remainder associated with division truncated toward zero. A zero divisor throws
99 * [ArithmeticException]. A nonzero remainder has the dividend's sign.
100 */
101 @Intrinsic("long_rem")
102 public override operator fun rem(other: Long): Long
104 /**
105 * Returns -1, 0, or 1 using signed mathematical ordering.
106 */
107 @NoGC
108 @Intrinsic("long_compare_to")
109 public override operator fun compareTo(other: Long): Long
111 /**
112 * Returns the bitwise intersection of the 64-bit operands.
113 */
114 @NoGC
115 @Intrinsic("long_and")
116 public infix fun and(other: Long): Long
118 /**
119 * Returns the bitwise union of the 64-bit operands.
120 */
121 @NoGC
122 @Intrinsic("long_or")
123 public infix fun or(other: Long): Long
125 /**
126 * Sets each result bit where the corresponding 64-bit operand bits differ.
127 */
128 @NoGC
129 @Intrinsic("long_xor")
130 public infix fun xor(other: Long): Long
132 /**
133 * Flips all 64 bits of the representation.
134 */
135 @NoGC
136 @Intrinsic("long_inv")
137 public fun inv(): Long
139 /**
140 * Shifts left using the low 6 bits of the Long count; shifted-out bits are discarded.
141 */
142 @NoGC
143 @Intrinsic("long_shl")
144 public infix fun shl(count: Long): Long
146 /**
147 * Shifts right using the low 6 bits of the Long count, replicating the sign bit.
148 */
149 @NoGC
150 @Intrinsic("long_shr")
151 public infix fun shr(count: Long): Long
153 /**
154 * Shifts right with zero fill using the low 6 bits of the Long count.
155 */
156 @NoGC
157 @Intrinsic("long_ushr")
158 public infix fun ushr(count: Long): Long
160 /**
161 * Converts modulo 2^8 and interprets the result as a 8-bit signed integer. The conversion
162 * always succeeds.
163 */
164 @NoGC
165 @Intrinsic("long_to_int8")
166 public fun toByte(): Byte
168 /**
169 * Converts modulo 2^16 and interprets the result as a 16-bit signed integer. The conversion
170 * always succeeds.
171 */
172 @NoGC
173 @Intrinsic("long_to_int16")
174 public fun toShort(): Short
176 /**
177 * Converts modulo 2^32 and interprets the result as a 32-bit signed integer. The conversion
178 * always succeeds.
179 */
180 @NoGC
181 @Intrinsic("long_to_int")
182 public fun toInt(): Int
184 /**
185 * Converts modulo 2^64 and interprets the result as a 64-bit signed integer. The conversion
186 * always succeeds.
187 */
188 @NoGC
189 @Intrinsic("long_to_long")
190 public fun toLong(): Long
192 /**
193 * Converts modulo 2^8 and interprets the result as a 8-bit unsigned integer. The conversion
194 * always succeeds.
195 */
196 @NoGC
197 @Intrinsic("long_to_uint8")
198 public fun toUByte(): UByte
200 /**
201 * Converts modulo 2^16 and interprets the result as a 16-bit unsigned integer. The conversion
202 * always succeeds.
203 */
204 @NoGC
205 @Intrinsic("long_to_uint16")
206 public fun toUShort(): UShort
208 /**
209 * Converts modulo 2^32 and interprets the result as a 32-bit unsigned integer. The conversion
210 * always succeeds.
211 */
212 @NoGC
213 @Intrinsic("long_to_uint")
214 public fun toUInt(): UInt
216 /**
217 * Converts modulo 2^64 and interprets the result as a 64-bit unsigned integer. The conversion
218 * always succeeds.
219 */
220 @NoGC
221 @Intrinsic("long_to_ulong")
222 public fun toULong(): ULong
224 /**
225 * Creates an ascending range including both this value and the endpoint.
226 */
227 public override operator fun rangeTo(endpoint: Long): LongRange =
228 LongRange(this, endpoint, 1L, false, true)
230 /**
231 * Creates an ascending range including this value and excluding the endpoint.
232 */
233 public override operator fun rangeUntil(endpoint: Long): LongRange =
234 LongRange(this, endpoint, 1L, false, false)
236 /**
237 * Creates an ascending range with an exclusive endpoint.
238 */
239 public infix fun until(endpoint: Long): LongRange =
240 LongRange(this, endpoint, 1L, false, false)
242 /**
243 * Creates a descending range including both endpoints.
244 */
245 public infix fun downTo(endpoint: Long): LongRange =
246 LongRange(this, endpoint, 1L, true, true)
248 /**
249 * Returns the locale-independent decimal representation of this integer.
250 */
251 public override fun toString(): String = coreLongToString(this)
253 /**
254 * Returns a hash consistent with same-type integer equality.
255 */
256 public override fun hash(): Long = coreLongHash(this)
258 /**
259 * Fixed representation bounds and the scalar encoding, decoding, and inspection protocols.
260 */
261 public companion object : ValueEncoder<Long>, ValueDecoder<Long>, ValueInspector<Long> {
262 /**
263 * Exposes the integer as a scalar value observation without reference identity.
264 */
265 public override fun inspect(value: Long): ValueView =
266 ValueObservation(typeInfo<Long>().type, None, { ValueShape.Scalar(ScalarValue.Signed(value)) })
268 /**
269 * The smallest representable 64-bit signed integer.
270 */
271 public const val MIN_VALUE: Long = -9223372036854775808L
272 /**
273 * The largest representable 64-bit signed integer.
274 */
275 public const val MAX_VALUE: Long = 9223372036854775807L
277 /**
278 * Writes the integer through the encoder's single-value container.
279 */
280 public override fun encode(value: Long, encoder: Encoder): Unit =
281 encoder.singleValue().writeLong(value.toLong())
283 /**
284 * Decodes an integer and rejects values outside the 64-bit signed range with
285 * [DecodingException].
286 */
287 public override fun decode(decoder: Decoder): Long =
288 decoder.singleValue().readLong()
289 }