scoop:scoop.core:0.1.0
src/integer_uint16.scoop
Selected production source · src/integer_uint16.scoop
1
/**2
* A 16-bit unsigned integer. Arithmetic wraps modulo 2^16; division by zero throws3
* [ArithmeticException]. Conversions are explicit and preserve the language's fixed-width rules on4
* every target.5
*/6
@Intrinsic("core_uint16")7
public struct UInt16 :8
Add<UInt16, UInt16>,9
Sub<UInt16, UInt16>,10
Mul<UInt16, UInt16>,11
Div<UInt16, UInt16>,12
Rem<UInt16, UInt16>,13
UnaryPlus<UInt16>,14
UnaryMinus<UInt16>,15
Increment<UInt16>,16
Decrement<UInt16>,17
Compare<UInt16>,18
RangeTo<UInt16, UIntRange>,19
RangeUntil<UInt16, UIntRange>,20
Equals<UInt16>, ToString, Hash {21
/**22
* Rounds the integer directly to IEEE binary32 using round-to-nearest, ties-to-even.23
*/24
@NoGC @Intrinsic("uint16_to_float")25
public fun toFloat(): Float27
/**28
* Rounds the integer directly to IEEE binary64 using round-to-nearest, ties-to-even.29
*/30
@NoGC @Intrinsic("uint16_to_double")31
public fun toDouble(): Double33
/**34
* Compares the mathematical values of two integers of the same type.35
*/36
@NoGC37
@Intrinsic("uint16_equals")38
public override operator fun equals(other: UInt16): Boolean41
/**42
* Returns the unchanged integer value.43
*/44
@NoGC45
@Intrinsic("uint16_unary_plus")46
public override operator fun unaryPlus(): UInt1648
/**49
* Returns the additive inverse modulo 2^16, including at the representation boundary.50
*/51
@NoGC52
@Intrinsic("uint16_unary_minus")53
public override operator fun unaryMinus(): UInt1655
/**56
* Returns the value plus one, wrapping modulo 2^16.57
*/58
@NoGC59
@Intrinsic("uint16_inc")60
public override operator fun inc(): UInt1662
/**63
* Returns the value minus one, wrapping modulo 2^16.64
*/65
@NoGC66
@Intrinsic("uint16_dec")67
public override operator fun dec(): UInt1669
/**70
* Returns the sum modulo 2^16; overflow does not throw.71
*/72
@NoGC73
@Intrinsic("uint16_add")74
public override operator fun plus(other: UInt16): UInt1676
/**77
* Returns the difference modulo 2^16; overflow does not throw.78
*/79
@NoGC80
@Intrinsic("uint16_sub")81
public override operator fun minus(other: UInt16): UInt1683
/**84
* Returns the product modulo 2^16; overflow does not throw.85
*/86
@NoGC87
@Intrinsic("uint16_mul")88
public override operator fun times(other: UInt16): UInt1690
/**91
* Returns the quotient truncated toward zero. A zero divisor throws [ArithmeticException].92
*/93
@Intrinsic("uint16_div")94
public override operator fun div(other: UInt16): UInt1696
/**97
* Returns the remainder associated with division truncated toward zero. A zero divisor throws98
* [ArithmeticException].99
*/100
@Intrinsic("uint16_rem")101
public override operator fun rem(other: UInt16): UInt16103
/**104
* Returns -1, 0, or 1 using unsigned mathematical ordering.105
*/106
@NoGC107
@Intrinsic("uint16_compare_to")108
public override operator fun compareTo(other: UInt16): Long110
/**111
* Returns the bitwise intersection of the 16-bit operands.112
*/113
@NoGC114
@Intrinsic("uint16_and")115
public infix fun and(other: UInt16): UInt16117
/**118
* Returns the bitwise union of the 16-bit operands.119
*/120
@NoGC121
@Intrinsic("uint16_or")122
public infix fun or(other: UInt16): UInt16124
/**125
* Sets each result bit where the corresponding 16-bit operand bits differ.126
*/127
@NoGC128
@Intrinsic("uint16_xor")129
public infix fun xor(other: UInt16): UInt16131
/**132
* Flips all 16 bits of the representation.133
*/134
@NoGC135
@Intrinsic("uint16_inv")136
public fun inv(): UInt16138
/**139
* Shifts left using the low 4 bits of the Long count; shifted-out bits are discarded.140
*/141
@NoGC142
@Intrinsic("uint16_shl")143
public infix fun shl(count: Long): UInt16145
/**146
* Shifts right using the low 4 bits of the Long count, filling with zero bits.147
*/148
@NoGC149
@Intrinsic("uint16_shr")150
public infix fun shr(count: Long): UInt16152
/**153
* Converts modulo 2^8 and interprets the result as a 8-bit signed integer. The conversion154
* always succeeds.155
*/156
@NoGC157
@Intrinsic("uint16_to_int8")158
public fun toByte(): Byte160
/**161
* Converts modulo 2^16 and interprets the result as a 16-bit signed integer. The conversion162
* always succeeds.163
*/164
@NoGC165
@Intrinsic("uint16_to_int16")166
public fun toShort(): Short168
/**169
* Converts modulo 2^32 and interprets the result as a 32-bit signed integer. The conversion170
* always succeeds.171
*/172
@NoGC173
@Intrinsic("uint16_to_int")174
public fun toInt(): Int176
/**177
* Converts modulo 2^64 and interprets the result as a 64-bit signed integer. The conversion178
* always succeeds.179
*/180
@NoGC181
@Intrinsic("uint16_to_long")182
public fun toLong(): Long184
/**185
* Converts modulo 2^8 and interprets the result as a 8-bit unsigned integer. The conversion186
* always succeeds.187
*/188
@NoGC189
@Intrinsic("uint16_to_uint8")190
public fun toUByte(): UByte192
/**193
* Converts modulo 2^16 and interprets the result as a 16-bit unsigned integer. The conversion194
* always succeeds.195
*/196
@NoGC197
@Intrinsic("uint16_to_uint16")198
public fun toUShort(): UShort200
/**201
* Converts modulo 2^32 and interprets the result as a 32-bit unsigned integer. The conversion202
* always succeeds.203
*/204
@NoGC205
@Intrinsic("uint16_to_uint")206
public fun toUInt(): UInt208
/**209
* Converts modulo 2^64 and interprets the result as a 64-bit unsigned integer. The conversion210
* always succeeds.211
*/212
@NoGC213
@Intrinsic("uint16_to_ulong")214
public fun toULong(): ULong216
/**217
* Creates an ascending range including both this value and the endpoint.218
*/219
public override operator fun rangeTo(endpoint: UInt16): UIntRange =220
UIntRange(this.toUInt(), endpoint.toUInt(), 1u, false, true)222
/**223
* Creates an ascending range including this value and excluding the endpoint.224
*/225
public override operator fun rangeUntil(endpoint: UInt16): UIntRange =226
UIntRange(this.toUInt(), endpoint.toUInt(), 1u, false, false)228
/**229
* Creates an ascending range with an exclusive endpoint.230
*/231
public infix fun until(endpoint: UInt16): UIntRange =232
UIntRange(this.toUInt(), endpoint.toUInt(), 1u, false, false)234
/**235
* Creates a descending range including both endpoints.236
*/237
public infix fun downTo(endpoint: UInt16): UIntRange =238
UIntRange(this.toUInt(), endpoint.toUInt(), 1u, true, true)240
/**241
* Returns the locale-independent decimal representation of this integer.242
*/243
public override fun toString(): String = coreULongToString(this.toULong())245
/**246
* Returns a hash consistent with same-type integer equality.247
*/248
public override fun hash(): Long {249
@Unsafe { return coreULongHash(this.toULong()) }250
}252
/**253
* Fixed representation bounds and the scalar encoding, decoding, and inspection protocols.254
*/255
public companion object : ValueEncoder<UInt16>, ValueDecoder<UInt16>, ValueInspector<UInt16> {256
/**257
* Exposes the integer as a scalar value observation without reference identity.258
*/259
public override fun inspect(value: UInt16): ValueView =260
ValueObservation(typeInfo<UInt16>().type, None, { ValueShape.Scalar(ScalarValue.Unsigned(value.toULong())) })262
/**263
* The smallest representable 16-bit unsigned integer.264
*/265
public const val MIN_VALUE: UInt16 = 0u266
/**267
* The largest representable 16-bit unsigned integer.268
*/269
public const val MAX_VALUE: UInt16 = 65535u271
/**272
* Writes the integer through the encoder's single-value container.273
*/274
public override fun encode(value: UInt16, encoder: Encoder): Unit =275
encoder.singleValue().writeULong(value.toULong())277
/**278
* Decodes an integer and rejects values outside the 16-bit unsigned range with279
* [DecodingException].280
*/281
public override fun decode(decoder: Decoder): UInt16 =282
decodeUnsigned(decoder, 65535UL).toUShort()283
}284
}