Long
class Long : Number, Comparable<Long>For Common, JVM, JS
Represents a 64-bit signed integer.
On the JVM, non-nullable values of this type are represented as values of the primitive type long.
For Native
Represents a 64-bit signed integer.
Functions
and
Performs a bitwise AND operation between the two values.
infix fun and(other: Long): LongcompareTo
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.
operator fun compareTo(other: Byte): Intoperator fun compareTo(other: Short): Intoperator fun compareTo(other: Int): Intoperator fun compareTo(other: Long): Intoperator fun compareTo(other: Float): Intoperator fun compareTo(other: Double): Intdec
Decrements this value.
operator fun dec(): Longdiv
Divides this value by the other value.
operator fun div(other: Byte): Longoperator fun div(other: Short): Longoperator fun div(other: Int): Longoperator fun div(other: Long): Longoperator fun div(other: Float): Floatoperator fun div(other: Double): Doubleequals
fun equals(other: Long): BooleanIndicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:
fun equals(other: Any?): BooleanhashCode
Returns a hash code value for the object. The general contract of hashCode is:
fun hashCode(): Intinc
Increments this value.
operator fun inc(): Longinv
Inverts the bits in this value.
fun inv(): Longminus
Subtracts the other value from this value.
operator fun minus(other: Byte): Longoperator fun minus(other: Short): Longoperator fun minus(other: Int): Longoperator fun minus(other: Long): Longoperator fun minus(other: Float): Floatoperator fun minus(other: Double): Doublemod
Calculates the remainder of dividing this value by the other value.
operator fun mod(other: Byte): Longoperator fun mod(other: Short): Longoperator fun mod(other: Int): Longoperator fun mod(other: Long): Longoperator fun mod(other: Float): Floatoperator fun mod(other: Double): Doubleor
Performs a bitwise OR operation between the two values.
infix fun or(other: Long): Longplus
Adds the other value to this value.
operator fun plus(other: Byte): Longoperator fun plus(other: Short): Longoperator fun plus(other: Int): Longoperator fun plus(other: Long): Longoperator fun plus(other: Float): Floatoperator fun plus(other: Double): Doublerem
Calculates the remainder of dividing this value by the other value.
operator fun rem(other: Byte): Longoperator fun rem(other: Short): Longoperator fun rem(other: Int): Longoperator fun rem(other: Long): Longoperator fun rem(other: Float): Floatoperator fun rem(other: Double): Doubleshr
Shifts this value right by the bitCount number of bits, filling the leftmost bits with copies of the sign bit.
infix fun shr(bitCount: Int): Longtimes
Multiplies this value by the other value.
operator fun times(other: Byte): Longoperator fun times(other: Short): Longoperator fun times(other: Int): Longoperator fun times(other: Long): Longoperator fun times(other: Float): Floatoperator fun times(other: Double): DoubletoLong
Returns this value.
fun toLong(): LongtoString
Returns a string representation of the object.
fun toString(): StringunaryMinus
Returns the negative of this value.
operator fun unaryMinus(): LongunaryPlus
Returns this value.
operator fun unaryPlus(): Longushr
Shifts this value right by the bitCount number of bits, filling the leftmost bits with zeros.
infix fun ushr(bitCount: Int): Longxor
Performs a bitwise XOR operation between the two values.
infix fun xor(other: Long): LongCompanion Object Properties
MAX_VALUE
A constant holding the maximum value an instance of Long can have.
const val MAX_VALUE: LongMIN_VALUE
A constant holding the minimum value an instance of Long can have.
const val MIN_VALUE: LongSIZE_BITS
The number of bits used to represent an instance of Long in a binary form.
const val SIZE_BITS: IntSIZE_BYTES
The number of bytes used to represent an instance of Long in a binary form.
const val SIZE_BYTES: IntExtension Properties
Extension Functions
coerceAtLeast
Ensures that this value is not less than the specified minimumValue.
fun Long.coerceAtLeast(minimumValue: Long): Longfun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): TcoerceAtMost
Ensures that this value is not greater than the specified maximumValue.
fun Long.coerceAtMost(maximumValue: Long): Longfun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): TcoerceIn
Ensures that this value lies in the specified range minimumValue..maximumValue.
fun Long.coerceIn(
minimumValue: Long,
maximumValue: Long
): Longfun <T : Comparable<T>> T.coerceIn(
minimumValue: T?,
maximumValue: T?
): TEnsures that this value lies in the specified range.
fun Long.coerceIn(range: ClosedRange<Long>): Longfun <T : Comparable<T>> T.coerceIn(
range: ClosedFloatingPointRange<T>
): Tfun <T : Comparable<T>> T.coerceIn(range: ClosedRange<T>): Tconvert
fun <R : Any> Long.convert(): RdownTo
Returns a progression from this value down to the specified to value with the step -1.
infix fun Long.downTo(to: Byte): LongProgressioninfix fun Long.downTo(to: Int): LongProgressioninfix fun Long.downTo(to: Long): LongProgressioninfix fun Long.downTo(to: Short): LongProgressionrangeTo
Creates a range from this Comparable value to the specified that value.
operator fun <T : Comparable<T>> T.rangeTo(
that: T
): ClosedRange<T>toBigDecimal
Returns the value of this Long number as a BigDecimal.
fun Long.toBigDecimal(): BigDecimalfun Long.toBigDecimal(mathContext: MathContext): BigDecimaltoBigInteger
Returns the value of this Long number as a BigInteger.
fun Long.toBigInteger(): BigIntegertoDuration
Returns a Duration equal to this Long number of the specified unit.
fun Long.toDuration(unit: DurationUnit): Duration