abstract struct Int

Overview

Int is the base type of all integer types.

There are four signed integer types: Int8, Int16, Int32 and Int64, being able to represent numbers of 8, 16, 32 and 64 bits respectively. There are four unsigned integer types: UInt8, UInt16, UInt32 and UInt64.

An integer literal is an optional #+ or #- sign, followed by a sequence of digits and underscores, optionally followed by a suffix. If no suffix is present, the literal's type is the lowest betwen Int32, Int64 and UInt64 in which the number fits:

1      # Int32

1_i8   # Int8
1_i16  # Int16
1_i32  # Int32
1_i64  # Int64

1_u8   # UInt8
1_u16  # UInt16
1_u32  # UInt32
1_u64  # UInt64

+10    # Int32
-20    # Int32

2147483648          # Int64
9223372036854775808 # UInt64

The underscore _ before the suffix is optional.

Underscores can be used to make some numbers more readable:

1_000_000 # better than 1000000

Binary numbers start with 0b:

0b1101 # == 13

Octal numbers start with 0o:

0o123 # == 83

Hexadecimal numbers start with 0x:

0xFE012D # == 16646445
0xfe012d # == 16646445

Superclass hierarchy

Object
Value
Number
Int

Included Modules

Comparable(BigInt)

Direct Known Subclasses

BigInt, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8

Defined in:

Instance Method Summary

Instance Method Detail

def %(other : BigInt)

def %(other : Int)

def *(other : BigInt)

def **(other : Int)

def **(other)

def +(other : BigInt)

def -(other : BigInt)

def /(other : BigInt)

def /(x : Int)

def <=>(other : BigInt)

def ===(char : Char)

def abs

def bit(bit)

def ceil

def day

def days

def divisible_by?(num)

def downto(n, &block : self -> )

def downto(n)

def even?

def fdiv(other)

def floor

def gcd(other : Int)

def hash

def hour

def hours

def lcm(other : Int)

def millisecond

def milliseconds

def minute

def minutes

def modulo(other)

def month

def months

def odd?

def remainder(other : Int)

def round

def second

def seconds

def succ

def times(&block : self -> )

def times

def to(n)

def to(n, &block : self -> )

def to_big_i

def to_json(io)

def to_s(base : Int, upcase = false : Bool)

def to_s

def to_s(io : IO)

def to_s(base : Int, io : IO, upcase = false : Bool)

def trunc

def upto(n, &block : self -> )

def upto(n)

def week

def weeks

def year

def years

def ~