struct BigRational

Overview

Rational numbers are represented as the quotient of arbitrarily large numerators and denominators. Rationals are canonicalized such that the denominator and the numerator have no common factors, and that the denominator is positive. Zero has the unique representation 0/1.

NOTE To use BigRational, you must explicitly import it with require "big"

require "big"

r = BigRational.new(7.to_big_i, 3.to_big_i)
r.to_s # => "7/3"

r = BigRational.new(3, -9)
r.to_s # => "-1/3"

It is implemented under the hood with GMP.

Included Modules

Defined in:

ssz/big_codec.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Number

hash_tree_root : Bytes hash_tree_root, ssz_basic? : Bool ssz_basic?, ssz_encode(io : IO) ssz_encode, ssz_size : Int32 ssz_size, ssz_variable? : Bool ssz_variable?

Class methods inherited from struct Number

ssz_basic? : Bool ssz_basic?, ssz_decode(io : IO, size : Int32 = 0) ssz_decode, ssz_variable? : Bool ssz_variable?

Instance methods inherited from class Object

ssz_basic? : Bool ssz_basic?, ssz_encode(io : IO)
ssz_encode : Bytes
ssz_encode
, ssz_fixed? : Bool ssz_fixed?, ssz_size : Int32 ssz_size, ssz_variable? : Bool ssz_variable?

Class methods inherited from class Object

ssz_basic? : Bool ssz_basic?, ssz_decode(io : IO, size : Int32 = 0)
ssz_decode(bytes : Bytes)
ssz_decode
, ssz_fixed? : Bool ssz_fixed?, ssz_variable? : Bool ssz_variable?

Class Method Detail

def self.ssz_basic? : Bool #

[View source]
def self.ssz_decode(io : IO, size : Int32) #

[View source]
def self.ssz_decode(bytes : Bytes) #

[View source]
def self.ssz_fixed? : Bool #

[View source]
def self.ssz_variable? : Bool #

[View source]

Instance Method Detail

def ssz_basic? : Bool #

[View source]
def ssz_encode(io : IO) #

[View source]
def ssz_encode : Bytes #

[View source]
def ssz_fixed? : Bool #

[View source]
def ssz_size : Int32 #

[View source]
def ssz_variable? : Bool #

[View source]