struct BigInt

Overview

A `BigInt` can represent arbitrarily large integers.

It is implemented under the hood with GMP.

big/big_int.cr

Instance Method Summary

, , , , ,

, , , , ,

, , , , ,

, , , , ,

Instance methods inherited from struct `Int`

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

, , , , ,

, , , , ,

Instance methods inherited from struct `Number`

, , , , , , , , , , , , , , , , , ,

, , , , ,

, , , , ,

,

Instance methods inherited from class `Object`

, , , , , , , , , , , , , , , , , ,

,

Class Method Detail

def self.new(str : String, base = 10) #

Creates a `BigInt` with the value denoted by str in the given base.

Raises `ArgumentError` if the string doesn't denote a valid integer.

``````BigInt.new("123456789123456789123456789123456789") # => 123456789123456789123456789123456789
BigInt.new("1234567890ABCDEF", base: 16)           # => 1311768467294899695``````

def self.new(num : Int::Signed) #

Creates a `BigInt` from the given num.

def self.new(num : Int::Unsigned) #

Creates a `BigInt` from the given num.

def self.new(num : Float) #

Creates a `BigInt` from the given num.

def self.new(num : BigInt) #

Returns num. Useful for generic code that does `T.new(...)` with `T` being a `Number`.

def self.new #

Creates a `BigInt` with the value zero.

``````require "big"
BigInt.new # => 0``````

Instance Method Detail

def %(other : Int) : BigInt #

def &(other : Int) : BigInt #

def *(other : BigInt) : BigInt #

def *(other : Int::Signed) : BigInt #

def *(other : Int::Unsigned) : BigInt #

def **(other : Int) : BigInt #

def +(other : BigInt) : BigInt #

def +(other : Int) : BigInt #

def -(other : BigInt) : BigInt #

def -(other : Int) : BigInt #

def - : BigInt #

def /(other : Int) : BigInt #

def <<(other : Int) : BigInt #

def <=>(other : BigInt) #

def <=>(other : Int::Signed) #

def <=>(other : Int::Unsigned) #

def <=>(other : Float) #

def >>(other : Int) : BigInt #

def ^(other : Int) : BigInt #

def abs : BigInt #

def clone #

def digits : Array(Int32) #

def gcd(other : BigInt) : BigInt #

def gcd(other : Int) : Int #

def hash #

def inspect #

def inspect(io) #

def lcm(other : BigInt) : BigInt #

def lcm(other : Int) : BigInt #

def popcount #

def remainder(other : Int) : BigInt #

def tdiv(other : Int) : BigInt #

def to_big_i #

def to_f #

def to_f32 #

def to_f64 #

def to_i #

def to_i16 #

def to_i32 #

def to_i64 #

def to_i8 #

def to_s(base : Int) #

Returns a string containing the representation of big radix base (2 through 36).

``````BigInt.new("123456789101101987654321").to_s(8)  # => "32111154373025463465765261"
BigInt.new("123456789101101987654321").to_s(16) # => "1a249b1f61599cd7eab1"
BigInt.new("123456789101101987654321").to_s(36) # => "k3qmt029k48nmpd"``````

def to_s #

Returns a string representation of self.

``BigInt.new("123456789101101987654321").to_s # => 123456789101101987654321``

def to_s(io) #

Returns a string representation of self.

``BigInt.new("123456789101101987654321").to_s # => 123456789101101987654321``

def to_u #

def to_u16 #

def to_u32 #

def to_u64 #

def to_u8 #

def to_unsafe #

def unsafe_floored_div(other : Int) : BigInt #

def unsafe_floored_div(other : BigInt) : BigInt #

def unsafe_floored_mod(other : BigInt) : BigInt #

def unsafe_floored_mod(other : Int) : BigInt #

def unsafe_truncated_div(other : BigInt) : BigInt #

def unsafe_truncated_div(other : Int) : BigInt #

def unsafe_truncated_mod(other : BigInt) : BigInt #

def unsafe_truncated_mod(other : Int) : BigInt #

def |(other : Int) : BigInt #

def ~ : BigInt #