File: long.kt

package info (click to toggle)
kotlin 1.3.31%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 109,908 kB
  • sloc: java: 454,756; xml: 18,599; javascript: 10,452; sh: 513; python: 97; makefile: 69; ansic: 4
file content (251 lines) | stat: -rw-r--r-- 11,090 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
 * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
 * that can be found in the license/LICENSE.txt file.
 */

package kotlin

/**
 * Represents a 64-bit signed integer.
 */
public class Long internal constructor(
    internal val low: Int,
    internal val high: Int
) : Number(), Comparable<Long> {

    companion object {
        /**
         * A constant holding the minimum value an instance of Long can have.
         */
        public const val MIN_VALUE: Long = -9223372036854775807L - 1L

        /**
         * A constant holding the maximum value an instance of Long can have.
         */
        public const val MAX_VALUE: Long = 9223372036854775807L
    }

    /**
     * Compares this value with the specified value for order.
     * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
     * or a positive number if it's greater than other.
     */
    public inline operator fun compareTo(other: Byte): Int = compareTo(other.toLong())

    /**
     * Compares this value with the specified value for order.
     * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
     * or a positive number if it's greater than other.
     */
    public inline operator fun compareTo(other: Short): Int = compareTo(other.toLong())

    /**
     * Compares this value with the specified value for order.
     * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
     * or a positive number if it's greater than other.
     */
    public inline operator fun compareTo(other: Int): Int = compareTo(other.toLong())

    /**
     * Compares this value with the specified value for order.
     * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
     * or a positive number if it's greater than other.
     */
    public override operator fun compareTo(other: Long): Int = compare(other)

    /**
     * Compares this value with the specified value for order.
     * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
     * or a positive number if it's greater than other.
     */
    public inline operator fun compareTo(other: Float): Int = toFloat().compareTo(other)

    /**
     * Compares this value with the specified value for order.
     * Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
     * or a positive number if it's greater than other.
     */
    public inline operator fun compareTo(other: Double): Int = toDouble().compareTo(other)

    /** Adds the other value to this value. */
    public inline operator fun plus(other: Byte): Long = plus(other.toLong())

    /** Adds the other value to this value. */
    public inline operator fun plus(other: Short): Long = plus(other.toLong())

    /** Adds the other value to this value. */
    public inline operator fun plus(other: Int): Long = plus(other.toLong())

    /** Adds the other value to this value. */
    public operator fun plus(other: Long): Long = add(other)

    /** Adds the other value to this value. */
    public inline operator fun plus(other: Float): Float = toFloat() + other

    /** Adds the other value to this value. */
    public inline operator fun plus(other: Double): Double = toDouble() + other

    /** Subtracts the other value from this value. */
    public inline operator fun minus(other: Byte): Long = minus(other.toLong())

    /** Subtracts the other value from this value. */
    public inline operator fun minus(other: Short): Long = minus(other.toLong())

    /** Subtracts the other value from this value. */
    public inline operator fun minus(other: Int): Long = minus(other.toLong())

    /** Subtracts the other value from this value. */
    public operator fun minus(other: Long): Long = subtract(other)

    /** Subtracts the other value from this value. */
    public inline operator fun minus(other: Float): Float = toFloat() - other

    /** Subtracts the other value from this value. */
    public inline operator fun minus(other: Double): Double = toDouble() - other

    /** Multiplies this value by the other value. */
    public inline operator fun times(other: Byte): Long = times(other.toLong())

    /** Multiplies this value by the other value. */
    public inline operator fun times(other: Short): Long = times(other.toLong())

    /** Multiplies this value by the other value. */
    public inline operator fun times(other: Int): Long = times(other.toLong())

    /** Multiplies this value by the other value. */
    public operator fun times(other: Long): Long = multiply(other)

    /** Multiplies this value by the other value. */
    public inline operator fun times(other: Float): Float = toFloat() * other

    /** Multiplies this value by the other value. */
    public inline operator fun times(other: Double): Double = toDouble() * other

    /** Divides this value by the other value. */
    public inline operator fun div(other: Byte): Long = div(other.toLong())

    /** Divides this value by the other value. */
    public inline operator fun div(other: Short): Long = div(other.toLong())

    /** Divides this value by the other value. */
    public inline operator fun div(other: Int): Long = div(other.toLong())

    /** Divides this value by the other value. */
    public operator fun div(other: Long): Long = divide(other)

    /** Divides this value by the other value. */
    public inline operator fun div(other: Float): Float = toFloat() / other

    /** Divides this value by the other value. */
    public inline operator fun div(other: Double): Double = toDouble() / other

    /** Calculates the remainder of dividing this value by the other value. */
    @Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.WARNING)
    public inline operator fun mod(other: Byte): Long = rem(other)

    /** Calculates the remainder of dividing this value by the other value. */
    @Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.WARNING)
    public inline operator fun mod(other: Short): Long = rem(other)

    /** Calculates the remainder of dividing this value by the other value. */
    @Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.WARNING)
    public inline operator fun mod(other: Int): Long = rem(other)

    /** Calculates the remainder of dividing this value by the other value. */
    @Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.WARNING)
    public inline operator fun mod(other: Long): Long = rem(other)

    /** Calculates the remainder of dividing this value by the other value. */
    @Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.WARNING)
    public inline operator fun mod(other: Float): Float = rem(other)

    /** Calculates the remainder of dividing this value by the other value. */
    @Deprecated("Use rem(other) instead", ReplaceWith("rem(other)"), DeprecationLevel.WARNING)
    public inline operator fun mod(other: Double): Double = rem(other)

    /** Calculates the remainder of dividing this value by the other value. */
    @SinceKotlin("1.1")
    public inline operator fun rem(other: Byte): Long = rem(other.toLong())

    /** Calculates the remainder of dividing this value by the other value. */
    @SinceKotlin("1.1")
    public inline operator fun rem(other: Short): Long = rem(other.toLong())

    /** Calculates the remainder of dividing this value by the other value. */
    @SinceKotlin("1.1")
    public inline operator fun rem(other: Int): Long = rem(other.toLong())

    /** Calculates the remainder of dividing this value by the other value. */
    @SinceKotlin("1.1")
    public operator fun rem(other: Long): Long = modulo(other)

    /** Calculates the remainder of dividing this value by the other value. */
    @SinceKotlin("1.1")
    public inline operator fun rem(other: Float): Float = toFloat() % other

    /** Calculates the remainder of dividing this value by the other value. */
    @SinceKotlin("1.1")
    public inline operator fun rem(other: Double): Double = toDouble() % other

    /** Increments this value. */
    public operator fun inc(): Long = this + 1L

    /** Decrements this value. */
    public operator fun dec(): Long = this - 1L

    /** Returns this value. */
    public inline operator fun unaryPlus(): Long = this

    /** Returns the negative of this value. */
    public operator fun unaryMinus(): Long = inv() + 1L

    /** Creates a range from this value to the specified [other] value. */
    public operator fun rangeTo(other: Byte): LongRange = rangeTo(other.toLong())

    /** Creates a range from this value to the specified [other] value. */
    public operator fun rangeTo(other: Short): LongRange = rangeTo(other.toLong())

    /** Creates a range from this value to the specified [other] value. */
    public operator fun rangeTo(other: Int): LongRange = rangeTo(other.toLong())

    /** Creates a range from this value to the specified [other] value. */
    public operator fun rangeTo(other: Long): LongRange = LongRange(this, other)

    /** Shifts this value left by the [bitCount] number of bits. */
    public infix fun shl(bitCount: Int): Long = shiftLeft(bitCount)

    /** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with copies of the sign bit. */
    public infix fun shr(bitCount: Int): Long = shiftRight(bitCount)

    /** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros. */
    public infix fun ushr(bitCount: Int): Long = shiftRightUnsigned(bitCount)

    /** Performs a bitwise AND operation between the two values. */
    public infix fun and(other: Long): Long = Long(low and other.low, high and other.high)

    /** Performs a bitwise OR operation between the two values. */
    public infix fun or(other: Long): Long = Long(low or other.low, high or other.high)

    /** Performs a bitwise XOR operation between the two values. */
    public infix fun xor(other: Long): Long = Long(low xor other.low, high xor other.high)

    /** Inverts the bits in this value. */
    public fun inv(): Long = Long(low.inv(), high.inv())

    public override fun toByte(): Byte = low.toByte()
    public override fun toChar(): Char = low.toChar()
    public override fun toShort(): Short = low.toShort()
    public override fun toInt(): Int = low
    public override fun toLong(): Long = this
    public override fun toFloat(): Float = toDouble().toFloat()
    public override fun toDouble(): Double = toNumber()

    // This method is used by `toString()`
    internal fun valueOf() = toDouble()

    override fun equals(other: Any?): Boolean = other is Long && equalsLong(other)

    override fun hashCode(): Int = hashCode(this)

    override fun toString(): String = toString(10)
}