scoop:scoop.core:0.1.0
src/integer_int16.scoop
Selected production source · src/integer_int16.scoop
1
/**2
* A 16-bit signed 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_int16")7
public struct Int16 :8
Add<Int16, Int16>,9
Sub<Int16, Int16>,10
Mul<Int16, Int16>,11
Div<Int16, Int16>,12
Rem<Int16, Int16>,13
UnaryPlus<Int16>,14
UnaryMinus<Int16>,15
Increment<Int16>,16
Decrement<Int16>,17
Compare<Int16>,18
RangeTo<Int16, IntRange>,19
RangeUntil<Int16, IntRange>,20
Equals<Int16>, ToString, Hash {21
/**22
* Rounds the integer directly to IEEE binary32 using round-to-nearest, ties-to-even.23
*/24
@NoGC @Intrinsic("int16_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("int16_to_double")31
public fun toDouble(): Double33
/**34
* Compares the mathematical values of two integers of the same type.35
*/36
@NoGC37
@Intrinsic("int16_equals")38
public override operator fun equals(other: Int16): Boolean41
/**42
* Returns the unchanged integer value.43
*/44
@NoGC45
@Intrinsic("int16_unary_plus")46
public override operator fun unaryPlus(): Int1648
/**49
* Returns the additive inverse modulo 2^16, including at the representation boundary.50
*/51
@NoGC52
@Intrinsic("int16_unary_minus")53
public override operator fun unaryMinus(): Int1655
/**56
* Returns the value plus one, wrapping modulo 2^16.57
*/58
@NoGC59
@Intrinsic("int16_inc")60
public override operator fun inc(): Int1662
/**63
* Returns the value minus one, wrapping modulo 2^16.64
*/65
@NoGC66
@Intrinsic("int16_dec")67
public override operator fun dec(): Int1669
/**70
* Returns the sum modulo 2^16; overflow does not throw.71
*/72
@NoGC73
@Intrinsic("int16_add")74
public override operator fun plus(other: Int16): Int1676
/**77
* Returns the difference modulo 2^16; overflow does not throw.78
*/79
@NoGC80
@Intrinsic("int16_sub")81
public override operator fun minus(other: Int16): Int1683
/**84
* Returns the product modulo 2^16; overflow does not throw.85
*/86
@NoGC87
@Intrinsic("int16_mul")88
public override operator fun times(other: Int16): Int1690
/**91
* Returns the quotient truncated toward zero. A zero divisor throws [ArithmeticException]. The92
* minimum value divided by -1 wraps to the minimum value.93
*/94
@Intrinsic("int16_div")95
public override operator fun div(other: Int16): Int1697
/**98
* Returns the remainder associated with division truncated toward zero. A zero divisor throws99
* [ArithmeticException]. A nonzero remainder has the dividend's sign.100
*/101
@Intrinsic("int16_rem")102
public override operator fun rem(other: Int16): Int16104
/**105
* Returns -1, 0, or 1 using signed mathematical ordering.106
*/107
@NoGC108
@Intrinsic("int16_compare_to")109
public override operator fun compareTo(other: Int16): Long111
/**112
* Returns the bitwise intersection of the 16-bit operands.113
*/114
@NoGC115
@Intrinsic("int16_and")116
public infix fun and(other: Int16): Int16118
/**119
* Returns the bitwise union of the 16-bit operands.120
*/121
@NoGC122
@Intrinsic("int16_or")123
public infix fun or(other: Int16): Int16125
/**126
* Sets each result bit where the corresponding 16-bit operand bits differ.127
*/128
@NoGC129
@Intrinsic("int16_xor")130
public infix fun xor(other: Int16): Int16132
/**133
* Flips all 16 bits of the representation.134
*/135
@NoGC136
@Intrinsic("int16_inv")137
public fun inv(): Int16139
/**140
* Shifts left using the low 4 bits of the Long count; shifted-out bits are discarded.141
*/142
@NoGC143
@Intrinsic("int16_shl")144
public infix fun shl(count: Long): Int16146
/**147
* Shifts right using the low 4 bits of the Long count, replicating the sign bit.148
*/149
@NoGC150
@Intrinsic("int16_shr")151
public infix fun shr(count: Long): Int16153
/**154
* Shifts right with zero fill using the low 4 bits of the Long count.155
*/156
@NoGC157
@Intrinsic("int16_ushr")158
public infix fun ushr(count: Long): Int16160
/**161
* Converts modulo 2^8 and interprets the result as a 8-bit signed integer. The conversion162
* always succeeds.163
*/164
@NoGC165
@Intrinsic("int16_to_int8")166
public fun toByte(): Byte168
/**169
* Converts modulo 2^16 and interprets the result as a 16-bit signed integer. The conversion170
* always succeeds.171
*/172
@NoGC173
@Intrinsic("int16_to_int16")174
public fun toShort(): Short176
/**177
* Converts modulo 2^32 and interprets the result as a 32-bit signed integer. The conversion178
* always succeeds.179
*/180
@NoGC181
@Intrinsic("int16_to_int")182
public fun toInt(): Int184
/**185
* Converts modulo 2^64 and interprets the result as a 64-bit signed integer. The conversion186
* always succeeds.187
*/188
@NoGC189
@Intrinsic("int16_to_long")190
public fun toLong(): Long192
/**193
* Converts modulo 2^8 and interprets the result as a 8-bit unsigned integer. The conversion194
* always succeeds.195
*/196
@NoGC197
@Intrinsic("int16_to_uint8")198
public fun toUByte(): UByte200
/**201
* Converts modulo 2^16 and interprets the result as a 16-bit unsigned integer. The conversion202
* always succeeds.203
*/204
@NoGC205
@Intrinsic("int16_to_uint16")206
public fun toUShort(): UShort208
/**209
* Converts modulo 2^32 and interprets the result as a 32-bit unsigned integer. The conversion210
* always succeeds.211
*/212
@NoGC213
@Intrinsic("int16_to_uint")214
public fun toUInt(): UInt216
/**217
* Converts modulo 2^64 and interprets the result as a 64-bit unsigned integer. The conversion218
* always succeeds.219
*/220
@NoGC221
@Intrinsic("int16_to_ulong")222
public fun toULong(): ULong224
/**225
* Creates an ascending range including both this value and the endpoint.226
*/227
public override operator fun rangeTo(endpoint: Int16): IntRange =228
IntRange(this.toInt(), endpoint.toInt(), 1, false, true)230
/**231
* Creates an ascending range including this value and excluding the endpoint.232
*/233
public override operator fun rangeUntil(endpoint: Int16): IntRange =234
IntRange(this.toInt(), endpoint.toInt(), 1, false, false)236
/**237
* Creates an ascending range with an exclusive endpoint.238
*/239
public infix fun until(endpoint: Int16): IntRange =240
IntRange(this.toInt(), endpoint.toInt(), 1, false, false)242
/**243
* Creates a descending range including both endpoints.244
*/245
public infix fun downTo(endpoint: Int16): IntRange =246
IntRange(this.toInt(), endpoint.toInt(), 1, true, true)248
/**249
* Returns the locale-independent decimal representation of this integer.250
*/251
public override fun toString(): String = coreLongToString(this.toLong())253
/**254
* Returns a hash consistent with same-type integer equality.255
*/256
public override fun hash(): Long {257
@Unsafe { return coreLongHash(this.toLong()) }258
}260
/**261
* Fixed representation bounds and the scalar encoding, decoding, and inspection protocols.262
*/263
public companion object : ValueEncoder<Int16>, ValueDecoder<Int16>, ValueInspector<Int16> {264
/**265
* Exposes the integer as a scalar value observation without reference identity.266
*/267
public override fun inspect(value: Int16): ValueView =268
ValueObservation(typeInfo<Int16>().type, None, { ValueShape.Scalar(ScalarValue.Signed(value.toLong())) })270
/**271
* The smallest representable 16-bit signed integer.272
*/273
public const val MIN_VALUE: Int16 = -32768274
/**275
* The largest representable 16-bit signed integer.276
*/277
public const val MAX_VALUE: Int16 = 32767279
/**280
* Writes the integer through the encoder's single-value container.281
*/282
public override fun encode(value: Int16, encoder: Encoder): Unit =283
encoder.singleValue().writeLong(value.toLong())285
/**286
* Decodes an integer and rejects values outside the 16-bit signed range with287
* [DecodingException].288
*/289
public override fun decode(decoder: Decoder): Int16 =290
decodeSigned(decoder, -32768L, 32767L).toShort()291
}292
}