Long

Common
JVM
JS
Native
1.0
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

Common
JVM
JS
Native
1.0

and

Performs a bitwise AND operation between the two values.

infix fun and(other: Long): Long
Common
JVM
JS
Native
1.0

compareTo

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): Int
operator fun compareTo(other: Short): Int
operator fun compareTo(other: Int): Int
operator fun compareTo(other: Long): Int
operator fun compareTo(other: Float): Int
operator fun compareTo(other: Double): Int
Common
JVM
JS
Native
1.0

dec

Returns this value decremented by one.

operator fun dec(): Long
Common
JVM
JS
Native
1.0

div

Divides this value by the other value, truncating the result to an integer that is closer to zero.

operator fun div(other: Byte): Long
operator fun div(other: Short): Long
operator fun div(other: Int): Long
operator fun div(other: Long): Long

Divides this value by the other value.

operator fun div(other: Float): Float
operator fun div(other: Double): Double

equals

Native
1.3
fun equals(other: Long): Boolean
Common
JVM
JS
Native
1.0

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

fun equals(other: Any?): Boolean
Native
1.3

hashCode

Returns a hash code value for the object. The general contract of hashCode is:

fun hashCode(): Int
Common
JVM
JS
Native
1.0

inc

Returns this value incremented by one.

operator fun inc(): Long
Common
JVM
JS
Native
1.0

inv

Inverts the bits in this value.

fun inv(): Long
Common
JVM
JS
Native
1.0

minus

Subtracts the other value from this value.

operator fun minus(other: Byte): Long
operator fun minus(other: Short): Long
operator fun minus(other: Int): Long
operator fun minus(other: Long): Long
operator fun minus(other: Float): Float
operator fun minus(other: Double): Double
Common
JVM
JS
Native
1.0

or

Performs a bitwise OR operation between the two values.

infix fun or(other: Long): Long
Common
JVM
JS
Native
1.0

plus

Adds the other value to this value.

operator fun plus(other: Byte): Long
operator fun plus(other: Short): Long
operator fun plus(other: Int): Long
operator fun plus(other: Long): Long
operator fun plus(other: Float): Float
operator fun plus(other: Double): Double
Common
JVM
JS
Native
1.0

rangeTo

Creates a range from this value to the specified other value.

operator fun rangeTo(other: Byte): LongRange
operator fun rangeTo(other: Short): LongRange
operator fun rangeTo(other: Int): LongRange
operator fun rangeTo(other: Long): LongRange
Common
JVM
JS
Native
1.9

rangeUntil

Creates a range from this value up to but excluding the specified other value.

operator fun rangeUntil(other: Byte): LongRange
operator fun rangeUntil(other: Short): LongRange
operator fun rangeUntil(other: Int): LongRange
operator fun rangeUntil(other: Long): LongRange
Common
JVM
JS
Native
1.1

rem

Calculates the remainder of truncating division of this value (dividend) by the other value (divisor).

operator fun rem(other: Byte): Long
operator fun rem(other: Short): Long
operator fun rem(other: Int): Long
operator fun rem(other: Long): Long
operator fun rem(other: Float): Float
operator fun rem(other: Double): Double
Common
JVM
JS
Native
1.0

shl

Shifts this value left by the bitCount number of bits.

infix fun shl(bitCount: Int): Long
Common
JVM
JS
Native
1.0

shr

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): Long
Common
JVM
JS
Native
1.0

times

Multiplies this value by the other value.

operator fun times(other: Byte): Long
operator fun times(other: Short): Long
operator fun times(other: Int): Long
operator fun times(other: Long): Long
operator fun times(other: Float): Float
operator fun times(other: Double): Double
Common
JVM
JS
Native
1.0

toByte

Converts this Long value to Byte.

fun toByte(): Byte
Common
JVM
JS
Native
1.0

toChar

Converts this Long value to Char.

fun toChar(): Char
Common
JVM
JS
Native
1.0

toDouble

Converts this Long value to Double.

fun toDouble(): Double
Common
JVM
JS
Native
1.0

toFloat

Converts this Long value to Float.

fun toFloat(): Float
Common
JVM
JS
Native
1.0

toInt

Converts this Long value to Int.

fun toInt(): Int
Common
JVM
JS
Native
1.0

toLong

Returns this value.

fun toLong(): Long
Common
JVM
JS
Native
1.0

toShort

Converts this Long value to Short.

fun toShort(): Short
Common
JVM
JS
Native
1.0

toString

Returns a string representation of the object.

fun toString(): String
Common
JVM
JS
Native
1.0

unaryMinus

Returns the negative of this value.

operator fun unaryMinus(): Long
Common
JVM
JS
Native
1.0

unaryPlus

Returns this value.

operator fun unaryPlus(): Long
Common
JVM
JS
Native
1.0

ushr

Shifts this value right by the bitCount number of bits, filling the leftmost bits with zeros.

infix fun ushr(bitCount: Int): Long
Common
JVM
JS
Native
1.0

xor

Performs a bitwise XOR operation between the two values.

infix fun xor(other: Long): Long

Companion Object Properties

Common
JVM
JS
Native
1.0

MAX_VALUE

A constant holding the maximum value an instance of Long can have.

const val MAX_VALUE: Long
Common
JVM
JS
Native
1.0

MIN_VALUE

A constant holding the minimum value an instance of Long can have.

const val MIN_VALUE: Long
Common
JVM
JS
Native
1.3

SIZE_BITS

The number of bits used to represent an instance of Long in a binary form.

const val SIZE_BITS: Int
Common
JVM
JS
Native
1.3

SIZE_BYTES

The number of bytes used to represent an instance of Long in a binary form.

const val SIZE_BYTES: Int

Extension Properties

Common
JVM
JS
Native
1.3

days

Returns a Duration equal to this Long number of days.

val Long.days: Duration
Common
JVM
JS
Native
1.3

hours

Returns a Duration equal to this Long number of hours.

val Long.hours: Duration
Common
JVM
JS
Native
1.3

microseconds

Returns a Duration equal to this Long number of microseconds.

val Long.microseconds: Duration
Common
JVM
JS
Native
1.3

milliseconds

Returns a Duration equal to this Long number of milliseconds.

val Long.milliseconds: Duration
Common
JVM
JS
Native
1.3

minutes

Returns a Duration equal to this Long number of minutes.

val Long.minutes: Duration
Common
JVM
JS
Native
1.3

nanoseconds

Returns a Duration equal to this Long number of nanoseconds.

val Long.nanoseconds: Duration
Common
JVM
JS
Native
1.3

seconds

Returns a Duration equal to this Long number of seconds.

val Long.seconds: Duration

Extension Functions

Common
JVM
JS
Native
1.0

coerceAtLeast

Ensures that this value is not less than the specified minimumValue.

fun Long.coerceAtLeast(minimumValue: Long): Long
fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T
Common
JVM
JS
Native
1.0

coerceAtMost

Ensures that this value is not greater than the specified maximumValue.

fun Long.coerceAtMost(maximumValue: Long): Long
fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T
Common
JVM
JS
Native
1.0

coerceIn

Ensures that this value lies in the specified range minimumValue..maximumValue.

fun Long.coerceIn(
    minimumValue: Long,
    maximumValue: Long
): Long
fun <T : Comparable<T>> T.coerceIn(
    minimumValue: T?,
    maximumValue: T?
): T

Ensures that this value lies in the specified range.

fun Long.coerceIn(range: ClosedRange<Long>): Long
fun <T : Comparable<T>> T.coerceIn(
    range: ClosedFloatingPointRange<T>
): T
fun <T : Comparable<T>> T.coerceIn(range: ClosedRange<T>): T
Common
JVM
JS
Native
1.6

compareTo

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.

infix fun <T> Comparable<T>.compareTo(other: T): Int
Native
1.3

convert

fun <R : Any> Long.convert(): R
Common
JVM
JS
Native
1.0

downTo

Returns a progression from this value down to the specified to value with the step -1.

infix fun Long.downTo(to: Byte): LongProgression
infix fun Long.downTo(to: Int): LongProgression
infix fun Long.downTo(to: Long): LongProgression
infix fun Long.downTo(to: Short): LongProgression
Common
JVM
JS
Native
1.5

floorDiv

Divides this value by the other value, flooring the result to an integer that is closer to negative infinity.

fun Long.floorDiv(other: Byte): Long
fun Long.floorDiv(other: Short): Long
fun Long.floorDiv(other: Int): Long
fun Long.floorDiv(other: Long): Long
Common
JVM
JS
Native
1.5

mod

Calculates the remainder of flooring division of this value (dividend) by the other value (divisor).

fun Long.mod(other: Byte): Byte
fun Long.mod(other: Short): Short
fun Long.mod(other: Int): Int
fun Long.mod(other: Long): Long
Native
1.3

narrow

fun <R : Number> Number.narrow(): R
Common
JVM
JS
Native
1.0

rangeTo

Creates a range from this Comparable value to the specified that value.

operator fun <T : Comparable<T>> T.rangeTo(
    that: T
): ClosedRange<T>
Common
JVM
JS
Native
1.9

rangeUntil

Creates an open-ended range from this Comparable value to the specified that value.

operator fun <T : Comparable<T>> T.rangeUntil(
    that: T
): OpenEndRange<T>
Native
1.3

signExtend

fun <R : Number> Number.signExtend(): R
JVM
1.2

toBigDecimal

Returns the value of this Long number as a BigDecimal.

fun Long.toBigDecimal(): BigDecimal
fun Long.toBigDecimal(mathContext: MathContext): BigDecimal
JVM
1.2

toBigInteger

Returns the value of this Long number as a BigInteger.

fun Long.toBigInteger(): BigInteger
Native
1.3

toCPointer

fun <T : CPointed> Long.toCPointer(): CPointer<T>?
Common
JVM
JS
Native
1.6

toDuration

Returns a Duration equal to this Long number of the specified unit.

fun Long.toDuration(unit: DurationUnit): Duration
Common
JVM
JS
Native
1.9

toHexString

Formats this Long value using the specified format.

fun Long.toHexString(
    format: HexFormat = HexFormat.Default
): String
Common
JVM
JS
Native
1.5

toUByte

Converts this Long value to UByte.

fun Long.toUByte(): UByte
Common
JVM
JS
Native
1.5

toUInt

Converts this Long value to UInt.

fun Long.toUInt(): UInt
Common
JVM
JS
Native
1.5

toULong

Converts this Long value to ULong.

fun Long.toULong(): ULong
Common
JVM
JS
Native
1.5

toUShort

Converts this Long value to UShort.

fun Long.toUShort(): UShort
Common
JVM
JS
Native
1.0

until

Returns a range from this value up to but excluding the specified to value.

infix fun Long.until(to: Byte): LongRange
infix fun Long.until(to: Int): LongRange
infix fun Long.until(to: Long): LongRange
infix fun Long.until(to: Short): LongRange