struct

Int64

Inherits Int / Comparable / Comparable / Comparable / Number / Comparable / Steppable / Comparable / Value / Object

Constants

MAX = 9223372036854775807_i64
MIN = -9223372036854775808_i64

Constructors

from_digits(digits : Enumerable(Int), base : Int = 10) : self

Returns a number for given digits and base. The digits are expected as an Enumerable with the least significant digit as the first element.

Base must not be less than 2.

All digits must be within 0...base.

Int64.from_digits([5, 4, 3, 2, 1])          # => 12345
Int64.from_digits([4, 6, 6, 0, 5], base: 7) # => 12345
Int64.from_digits([45, 23, 1], base: 100)   # => 12345

Int64.from_digits([1], base: -2) # raises ArgumentError
Int64.from_digits([-1])          # raises ArgumentError
Int64.from_digits([3], base: 2)  # raises ArgumentError
Source
new(value : String, base : Int = 10, whitespace : Bool = true, underscore : Bool = false, prefix : Bool = false, strict : Bool = true, leading_zero_is_octal : Bool = false) : self

Returns an Int64 by invoking to_i64 on value. See String#to_i for more details.

Int64.new "20"                        # => 20
Int64.new "  20  ", whitespace: false # raises ArgumentError: Invalid Int64: "  20  "
Source
new(value) : self

Returns an Int64 by invoking to_i64 on value.

Source
new!(value) : self

Returns an Int64 by invoking to_i64! on value.

Source

Class methods

from_json_object_key?(key : String)
Source

Instance methods

!=(other : Int8) : Bool

Returns true if self is not equal to other.

Source
!=(other : Int16) : Bool

Returns true if self is not equal to other.

Source
!=(other : Int32) : Bool

Returns true if self is not equal to other.

Source
!=(other : Int64) : Bool

Returns true if self is not equal to other.

Source
!=(other : Int128) : Bool

Returns true if self is not equal to other.

Source
!=(other : UInt8) : Bool

Returns true if self is not equal to other.

Source
!=(other : UInt16) : Bool

Returns true if self is not equal to other.

Source
!=(other : UInt32) : Bool

Returns true if self is not equal to other.

Source
!=(other : UInt64) : Bool

Returns true if self is not equal to other.

Source
!=(other : UInt128) : Bool

Returns true if self is not equal to other.

Source
!=(other : Float32) : Bool

Returns true if self is not equal to other or if self and other are unordered.

Source
!=(other : Float64) : Bool

Returns true if self is not equal to other or if self and other are unordered.

Source
&(other : Int8) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : Int16) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : Int32) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : Int64) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : Int128) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : UInt8) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : UInt16) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : UInt32) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : UInt64) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&(other : UInt128) : self

Returns the result of performing a bitwise AND of self's and other's bits.

Source
&*(other : Int8) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : Int16) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : Int32) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : Int64) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : Int128) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : UInt8) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : UInt16) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : UInt32) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : UInt64) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&*(other : UInt128) : self

Returns the result of multiplying self and other. In case of overflow a wrapping is performed.

Source
&+(other : Int8) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : Int16) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : Int32) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : Int64) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : Int128) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : UInt8) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : UInt16) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : UInt32) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : UInt64) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&+(other : UInt128) : self

Returns the result of adding self and other. In case of overflow a wrapping is performed.

Source
&-(other : Int8) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : Int16) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : Int32) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : Int64) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : Int128) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : UInt8) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : UInt16) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : UInt32) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : UInt64) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
&-(other : UInt128) : self

Returns the result of subtracting self and other. In case of overflow a wrapping is performed.

Source
*(other : Int8) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : Int16) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : Int32) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : Int64) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : Int128) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : UInt8) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : UInt16) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : UInt32) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : UInt64) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : UInt128) : self

Returns the result of multiplying self and other. Raises OverflowError in case of overflow.

Source
*(other : Float32) : Float32

Returns the result of multiplying self and other.

Source
*(other : Float64) : Float64

Returns the result of multiplying self and other.

Source
+(other : Int8) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : Int16) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : Int32) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : Int64) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : Int128) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : UInt8) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : UInt16) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : UInt32) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : UInt64) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : UInt128) : self

Returns the result of adding self and other. Raises OverflowError in case of overflow.

Source
+(other : Float32) : Float32

Returns the result of adding self and other.

Source
+(other : Float64) : Float64

Returns the result of adding self and other.

Source
-(other : Int8) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : Int16) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : Int32) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : Int64) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : Int128) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : UInt8) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : UInt16) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : UInt32) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : UInt64) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : UInt128) : self

Returns the result of subtracting self and other. Raises OverflowError in case of overflow.

Source
-(other : Float32) : Float32

Returns the result of subtracting self and other.

Source
-(other : Float64) : Float64

Returns the result of subtracting self and other.

Source
/(other : Int8) : Float64
Source
/(other : UInt8) : Float64
Source
/(other : Int16) : Float64
Source
/(other : UInt16) : Float64
Source
/(other : Int32) : Float64
Source
/(other : UInt32) : Float64
Source
/(other : Int64) : Float64
Source
/(other : UInt64) : Float64
Source
/(other : Int128) : Float64
Source
/(other : UInt128) : Float64
Source
/(other : Float32) : Float32
Source
/(other : Float64) : Float64
Source
/(other : BigInt) : BigFloat
Source
<(other : Int8) : Bool

Returns true if self is less than other.

Source
<(other : Int16) : Bool

Returns true if self is less than other.

Source
<(other : Int32) : Bool

Returns true if self is less than other.

Source
<(other : Int64) : Bool

Returns true if self is less than other.

Source
<(other : Int128) : Bool

Returns true if self is less than other.

Source
<(other : UInt8) : Bool

Returns true if self is less than other.

Source
<(other : UInt16) : Bool

Returns true if self is less than other.

Source
<(other : UInt32) : Bool

Returns true if self is less than other.

Source
<(other : UInt64) : Bool

Returns true if self is less than other.

Source
<(other : UInt128) : Bool

Returns true if self is less than other.

Source
<(other : Float32) : Bool

Returns true if self is less than other.

Source
<(other : Float64) : Bool

Returns true if self is less than other.

Source
<=(other : Int8) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : Int16) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : Int32) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : Int64) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : Int128) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : UInt8) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : UInt16) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : UInt32) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : UInt64) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : UInt128) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : Float32) : Bool

Returns true if self is less than or equal to other.

Source
<=(other : Float64) : Bool

Returns true if self is less than or equal to other.

Source
==(other : Int8) : Bool

Returns true if self is equal to other.

Source
==(other : Int16) : Bool

Returns true if self is equal to other.

Source
==(other : Int32) : Bool

Returns true if self is equal to other.

Source
==(other : Int64) : Bool

Returns true if self is equal to other.

Source
==(other : Int128) : Bool

Returns true if self is equal to other.

Source
==(other : UInt8) : Bool

Returns true if self is equal to other.

Source
==(other : UInt16) : Bool

Returns true if self is equal to other.

Source
==(other : UInt32) : Bool

Returns true if self is equal to other.

Source
==(other : UInt64) : Bool

Returns true if self is equal to other.

Source
==(other : UInt128) : Bool

Returns true if self is equal to other.

Source
==(other : Float32) : Bool

Returns true if self is equal to other.

Source
==(other : Float64) : Bool

Returns true if self is equal to other.

Source
>(other : Int8) : Bool

Returns true if self is greater than other.

Source
>(other : Int16) : Bool

Returns true if self is greater than other.

Source
>(other : Int32) : Bool

Returns true if self is greater than other.

Source
>(other : Int64) : Bool

Returns true if self is greater than other.

Source
>(other : Int128) : Bool

Returns true if self is greater than other.

Source
>(other : UInt8) : Bool

Returns true if self is greater than other.

Source
>(other : UInt16) : Bool

Returns true if self is greater than other.

Source
>(other : UInt32) : Bool

Returns true if self is greater than other.

Source
>(other : UInt64) : Bool

Returns true if self is greater than other.

Source
>(other : UInt128) : Bool

Returns true if self is greater than other.

Source
>(other : Float32) : Bool

Returns true if self is greater than other.

Source
>(other : Float64) : Bool

Returns true if self is greater than other.

Source
>=(other : Int8) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : Int16) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : Int32) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : Int64) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : Int128) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : UInt8) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : UInt16) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : UInt32) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : UInt64) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : UInt128) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : Float32) : Bool

Returns true if self is greater than or equal to other.

Source
>=(other : Float64) : Bool

Returns true if self is greater than or equal to other.

Source
^(other : Int8) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : Int16) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : Int32) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : Int64) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : Int128) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : UInt8) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : UInt16) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : UInt32) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : UInt64) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
^(other : UInt128) : self

Returns the result of performing a bitwise XOR of self's and other's bits.

Source
|(other : Int8) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : Int16) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : Int32) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : Int64) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : Int128) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : UInt8) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : UInt16) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : UInt32) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : UInt64) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
|(other : UInt128) : self

Returns the result of performing a bitwise OR of self's and other's bits.

Source
abs_unsigned

Returns the absolute value of self as an unsigned value of the same size.

Returns self if self is already an Int::Unsigned. This method never overflows.

1_u32.abs_unsigned      # => 1_u32
2_i32.abs_unsigned      # => 2_u32
-3_i8.abs_unsigned      # => 3_u8
Int16::MIN.abs_unsigned # => 32768_u16
Source
bit_reverse

Reverses the bits of self; the least significant bit becomes the most significant, and vice-versa.

0b01001011_u8.bit_reverse          # => 0b11010010
0b1100100001100111_u16.bit_reverse # => 0b1110011000010011
Source
byte_swap

Swaps the bytes of self; a little-endian value becomes a big-endian value, and vice-versa. The bit order within each byte is unchanged.

Has no effect on 8-bit integers.

0x12345678_i64.byte_swap         # => 0x7856341200000000
0x123456789ABCDEF0_i64.byte_swap # => -0xf21436587a9cbee
Source
clone
Source
leading_zeros_count

Returns the number of leading 0-bits.

Source
neg_signed

Returns the negative of self as a signed value of the same size.

Returns -self if self is already an Int::Signed. Raises OverflowError in case of overflow.

1_i32.neg_signed      # => -1_i32
2_u16.neg_signed      # => -2_i16
128_u8.neg_signed     # => -128_i8
Int16::MIN.neg_signed # raises OverflowError
Source
popcount

Counts 1-bits in the binary representation of this integer.

5.popcount   # => 2
-15.popcount # => 29
Source
rotate_left(n : Int) : self

Returns the bitwise rotation of self n times in the most significant bit's direction. Negative shifts are equivalent to rotate_right(-n).

0b01001101_u8.rotate_left(3)  # => 0b01101010
0b01001101_u8.rotate_left(8)  # => 0b01001101
0b01001101_u8.rotate_left(11) # => 0b01101010
0b01001101_u8.rotate_left(-1) # => 0b10100110
Source
rotate_right(n : Int) : self

Returns the bitwise rotation of self n times in the least significant bit's direction. Negative shifts are equivalent to rotate_left(-n).

0b01001101_u8.rotate_right(3)  # => 0b10101001
0b01001101_u8.rotate_right(8)  # => 0b01001101
0b01001101_u8.rotate_right(11) # => 0b10101001
0b01001101_u8.rotate_right(-1) # => 0b10011010
Source
to_f

Returns self converted to Float64. Raises OverflowError in case of overflow.

Source
to_f!

Returns self converted to Float64. In case of overflow a wrapping is performed.

Source
to_f32

Returns self converted to Float32. Raises OverflowError in case of overflow.

Source
to_f32!

Returns self converted to Float32. In case of overflow a wrapping is performed.

Source
to_f64

Returns self converted to Float64. Raises OverflowError in case of overflow.

Source
to_f64!

Returns self converted to Float64. In case of overflow a wrapping is performed.

Source
to_i

Returns self converted to Int32. Raises OverflowError in case of overflow.

Source
to_i!

Returns self converted to Int32. In case of overflow a wrapping is performed.

Source
to_i128

Returns self converted to Int128. Raises OverflowError in case of overflow.

Source
to_i128!

Returns self converted to Int128. In case of overflow a wrapping is performed.

Source
to_i16

Returns self converted to Int16. Raises OverflowError in case of overflow.

Source
to_i16!

Returns self converted to Int16. In case of overflow a wrapping is performed.

Source
to_i32

Returns self converted to Int32. Raises OverflowError in case of overflow.

Source
to_i32!

Returns self converted to Int32. In case of overflow a wrapping is performed.

Source
to_i64

Returns self converted to Int64. Raises OverflowError in case of overflow.

Source
to_i64!

Returns self converted to Int64. In case of overflow a wrapping is performed.

Source
to_i8

Returns self converted to Int8. Raises OverflowError in case of overflow.

Source
to_i8!

Returns self converted to Int8. In case of overflow a wrapping is performed.

Source
to_signed

Returns self converted to a signed value of the same size.

Simply returns self unmodified if self is already an Int::Signed. Raises OverflowError in case of overflow.

1_u32.to_signed # => 1_i32
2_u16.to_signed # => 2_i16
3_i64.to_signed # => 3_i64
Source
to_signed!

Returns self converted to a signed value of the same size, wrapping in case of overflow.

Simply returns self unmodified if self is already an Int::Signed.

1_u32.to_signed!     # => 1_i32
65530_u16.to_signed! # => -6_i16
3_i64.to_signed!     # => 3_i64
Source
to_u

Returns self converted to UInt32. Raises OverflowError in case of overflow.

Source
to_u!

Returns self converted to UInt32. In case of overflow a wrapping is performed.

Source
to_u128

Returns self converted to UInt128. Raises OverflowError in case of overflow.

Source
to_u128!

Returns self converted to UInt128. In case of overflow a wrapping is performed.

Source
to_u16

Returns self converted to UInt16. Raises OverflowError in case of overflow.

Source
to_u16!

Returns self converted to UInt16. In case of overflow a wrapping is performed.

Source
to_u32

Returns self converted to UInt32. Raises OverflowError in case of overflow.

Source
to_u32!

Returns self converted to UInt32. In case of overflow a wrapping is performed.

Source
to_u64

Returns self converted to UInt64. Raises OverflowError in case of overflow.

Source
to_u64!

Returns self converted to UInt64. In case of overflow a wrapping is performed.

Source
to_u8

Returns self converted to UInt8. Raises OverflowError in case of overflow.

Source
to_u8!

Returns self converted to UInt8. In case of overflow a wrapping is performed.

Source
to_unsigned

Returns self converted to an unsigned value of the same size.

Simply returns self unmodified if self is already an Int::Unsigned. Raises OverflowError in case of overflow.

1_i32.to_unsigned # => 1_u32
2_i16.to_unsigned # => 2_u16
3_u64.to_unsigned # => 3_u64
Source
to_unsigned!

Returns self converted to an unsigned value of the same size, wrapping in case of overflow.

Simply returns self unmodified if self is already an Int::Unsigned.

1_i32.to_unsigned!    # => 1_u32
(-6_i16).to_unsigned! # => 65530_u16
3_u64.to_unsigned!    # => 3_u64
Source
trailing_zeros_count

Returns the number of trailing 0-bits.

Source
unsafe_chr

Returns a Char that has the unicode codepoint of self, without checking if this integer is in the range valid for chars (0..0xd7ff and 0xe000..0x10ffff). In case of overflow a wrapping is performed.

You should never use this method unless chr turns out to be a bottleneck.

97.unsafe_chr # => 'a'
Source