- README

- Top Level Namespace
- Adler32
- ArgumentError
- Array
- Atomic
- Base64
  - Error
- Benchmark
  - BM
    - Job
    - Tms
  - IPS
    - Entry
    - Job
- BigFloat
- BigInt
- BigRational
- BitArray
- Bool
- Box
- Bytes
- Channel
  - Buffered
  - ClosedError
  - ReceiveAction
  - SelectAction
  - SendAction
  - Unbuffered
- Char
  - Reader
- Class
- Colorize
  - Object
  - ObjectExtensions
- Comparable
- Complex
- Concurrent
  - CanceledError
- CRC32
- Crypto
  - Bcrypt
    - Error
    - Password
  - Blowfish
  - Subtle
- Crystal
  - Macros
    - And
    - Arg
    - ArrayLiteral
    - Assign
    - ASTNode
    - BinaryOp
    - Block
    - BoolLiteral
    - Call
    - Case
    - Cast
    - CharLiteral
    - ClassDef
    - ClassVar
    - Def
    - Expressions
    - Generic
    - Global
    - HashLiteral
    - If
    - ImplicitObj
    - InstanceSizeOf
    - InstanceVar
    - IsA
    - Macro
    - MacroId
    - MetaVar
    - MultiAssign
    - NamedArgument
    - NamedTupleLiteral
    - NilableCast
    - NilLiteral
    - Nop
    - Not
    - NumberLiteral
    - Or
    - Out
    - Path
    - PointerOf
    - RangeLiteral
    - ReadInstanceVar
    - RegexLiteral
    - Require
    - RespondsTo
    - SizeOf
    - Splat
    - StringInterpolation
    - StringLiteral
    - SymbolLiteral
    - TupleLiteral
    - TypeDeclaration
    - TypeNode
    - UnaryExpression
    - UninitializedVar
    - Union
    - Var
    - VisibilityModifier
    - When
    - While
  - System
- CSV
  - Builder
    - Row
  - Error
  - Lexer
  - MalformedCSVError
  - Parser
  - Row
  - Token
    - Kind
- Debug
  - DWARF
    - Abbrev
      - Attribute
    - AT
    - FORM
    - Info
      - Value
    - LineNumbers
      - Register
      - Row
      - Sequence
    - LNE
    - LNS
    - Strings
    - TAG
  - ELF
    - Endianness
    - Error
    - Ident
    - Klass
    - Machine
    - OSABI
    - SectionHeader
      - Flags
      - Type
    - Type
- Deque
- Digest
  - Base
  - MD5
  - SHA1
- Dir
- DivisionByZero
- DL
- ECR
- Enum
- Enumerable
  - EmptyError
- ENV
- Errno
- Exception
- Fiber
- File
  - Stat
- FileUtils
- Flate
  - Error
  - Reader
  - Strategy
  - Writer
- Float
  - Primitive
  - Printer
    - CachedPowers
      - Power
    - DiyFP
    - Grisu3
    - IEEE
- Float32
- Float64
- GC
  - Stats
- Gzip
  - Error
  - Header
  - Reader
  - Writer
- Hash
- HTML
- HTTP
  - Client
    - BodyType
    - Response
  - CompressHandler
  - ComputedContentTypeHeader
  - Cookie
  - Cookies
  - ErrorHandler
  - FormData
    - Builder
    - Error
    - FileMetadata
    - Parser
    - Part
  - Handler
    - Proc
  - Headers
  - LogHandler
  - Multipart
    - Builder
    - Error
    - Parser
  - Params
    - Builder
  - Request
  - Server
    - Context
    - RequestProcessor
    - Response
  - StaticFileHandler
    - DirectoryListing
  - WebSocket
  - WebSocketHandler
- Indexable
- IndexError
- INI
- Int
  - Primitive
  - Signed
  - Unsigned
- Int16
- Int32
- Int64
- Int8
- InvalidByteSequenceError
- IO
  - Buffered
  - ByteFormat
    - BigEndian
    - LittleEndian
    - NetworkEndian
    - SystemEndian
  - Delimited
  - EncodingOptions
  - EOFError
  - Error
  - FileDescriptor
  - Hexdump
  - Memory
  - MultiWriter
  - Seek
  - Sized
  - Timeout
- IPSocket
- Iterable
- Iterator
  - IteratorWrapper
  - Stop
- JSON
  - Any
  - Builder
    - ArrayState
    - DocumentEndState
    - DocumentStartState
    - ObjectState
    - StartState
    - State
  - Error
  - Lexer
  - ParseException
  - Parser
  - PullParser
  - Token
  - Type
- KeyError
- Levenshtein
  - Finder
- LLVM
  - ABI
    - AArch64
    - ArgKind
    - ArgType
    - ARM
    - FunctionType
    - X86
    - X86_64
      - RegClass
  - AtomicOrdering
  - AtomicRMWBinOp
  - Attribute
  - AttributeIndex
  - BasicBlock
  - BasicBlockCollection
  - Builder
  - CallConvention
  - CodeGenFileType
  - CodeGenOptLevel
  - CodeModel
  - Context
  - DIBuilder
  - DIFlags
  - DwarfTag
  - DwarfTypeEncoding
  - Function
  - FunctionCollection
  - FunctionPassManager
    - Runner
  - GenericValue
  - GlobalCollection
  - InstructionCollection
  - IntPredicate
  - JITCompiler
  - Linkage
  - MemoryBuffer
  - Module
  - ModuleFlag
  - ModulePassManager
  - OperandBundleDef
  - ParameterCollection
  - PassManagerBuilder
  - PassRegistry
  - PhiTable
  - RealPredicate
  - RelocMode
  - Target
  - TargetData
  - TargetMachine
  - Type
    - Kind
  - Value
    - Kind
  - ValueMethods
  - VerifierFailureAction
- Logger
  - Formatter
  - Severity
- Markdown
  - HTMLRenderer
  - Parser
    - PrefixHeader
    - UnorderedList
  - Renderer
- Math
- Mutex
- NamedTuple
- Nil
- Number
  - Primitive
- OAuth
  - AccessToken
  - Consumer
  - Error
  - RequestToken
- OAuth2
  - AccessToken
    - Bearer
    - Mac
  - Client
  - Error
  - Session
- Object
- OpenSSL
  - Digest
    - Error
    - UnsupportedError
  - DigestBase
  - DigestIO
    - DigestMode
  - Error
  - HMAC
  - MD5
  - SHA1
  - SSL
    - Context
      - Client
      - Server
    - Error
    - ErrorType
    - Modes
    - Options
    - Socket
      - Client
      - Server
    - VerifyMode
    - X509VerifyFlags
- OptionParser
  - Exception
  - InvalidOption
  - MissingOption
- PartialComparable
- Pointer
  - Appender
- PrettyPrint
- Proc
- Process
  - Env
  - Status
  - Stdio
  - Tms
- Random
  - ISAAC
  - MT19937
  - PCG32
  - System
- Range
- Readline
  - CompletionProc
  - KeyBindingProc
- Reference
- Reflect
- Regex
  - MatchData
  - Options
- SecureRandom
- Set
- Signal
- Slice
- Socket
  - Address
  - Addrinfo
  - Error
  - Family
  - IPAddress
  - Protocol
  - Server
  - Type
  - UNIXAddress
- Spec
  - Expectations
  - Methods
  - ObjectExtensions
- StaticArray
- String
  - Builder
  - RawConverter
- StringPool
- StringScanner
- Struct
- Symbol
- System
- TCPServer
- TCPSocket
- Tempfile
- Termios
  - AttributeSelection
  - BaudRate
  - ControlMode
  - InputMode
  - LineControl
  - LocalMode
  - OutputMode
- Time
  - DayOfWeek
  - EpochConverter
  - EpochMillisConverter
  - Format
    - Error
  - Kind
  - MonthSpan
  - Span
- Tuple
- TypeCastError
- UDPSocket
- UInt16
- UInt32
- UInt64
- UInt8
- Unicode
  - CaseOptions
- Union
- UNIXServer
- UNIXSocket
- URI
  - Error
- Value
- WeakRef
- XML
  - Attributes
  - AttributeType
  - Builder
  - Error
  - HTMLParserOptions
  - Namespace
  - Node
  - NodeSet
  - ParserOptions
  - Reader
  - SaveOptions
  - Type
  - XPathContext
- YAML
  - Any
  - Builder
  - Error
  - EventKind
  - ParseException
  - Parser
  - PullParser
  - Type
- Zip
  - CompressionMethod
  - Error
  - File
    - Entry
  - FileInfo
  - Reader
    - Entry
  - Writer
    - Entry
- Zlib
  - Error
  - Reader
  - Writer

# struct BigRational

- BigRational
- Number
- Value
- Object

## 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.

    require "big_rational"

    r = BigRational.new(BigInt.new(7), BigInt.new(3))
    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

- Comparable(Float)
- Comparable(Int)
- Comparable(BigRational)

## Defined in:

## Constructors

- .new(numerator : Int, denominator : Int)

  Create a new `BigRational`.

- .new(num : Int)

  Creates a new `BigRational` with num as the numerator and 1 for denominator.

## Instance Method Summary

- #*(other : BigRational)
- #*(other : Int)
- #+(other : BigRational)
- #+(other : Int)
- #-(other : BigRational)
- #-(other : Int)
- #-
- #/(other : Int)
- #/(other : BigRational)
- #<<(other : Int)

  Multiplies the rational by (2 ** other)

- #<=>(other : BigRational)
- #<=>(other : Float)
- #<=>(other : Int)
- #>>(other : Int)

  Divides the rational by (2 ** other)

- #abs
- #clone
- #denominator
- #hash
- #inspect
- #inspect(io)
- #inv

  Returns a new `BigRational` as 1/r.

- #numerator
- #to_f

  Returns the `Float64` representing this rational.

- #to_f32
- #to_f64
- #to_s(io : IO, base = 10)
- #to_s(base = 10)

  Returns the string representing this rational.

- #to_unsafe

### Instance methods inherited from module `Comparable(Float)`

<(other : T) <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) >, >=(other : T) >=

### Instance methods inherited from module `Comparable(Int)`

<(other : T) <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) >, >=(other : T) >=

### Instance methods inherited from module `Comparable(BigRational)`

<(other : T) <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) >, >=(other : T) >=

### Instance methods inherited from struct `Number`

*(other : Complex)
*(other : BigFloat) *, +(other : BigFloat)
+(other : Complex)
+ +, -(other : Complex)
-(other : BigFloat) -, /(other : Complex) /, <=>(other : BigFloat)
<=>(other) <=>, ==(other : Complex) ==, abs abs, abs2 abs2, cis cis, clamp(min, max)
clamp(range : Range) clamp, divmod(number) divmod, i i, round(digits, base = 10) round, sign sign, significant(digits, base = 10) significant, step(*, to = nil, by = 1)
step(*, to = nil, by = 1, &block) step, to_big_f to_big_f, to_c to_c, to_yaml(yaml : YAML::Builder) to_yaml, zero? : Bool zero?

### Constructor methods inherited from struct `Number`

zero : self zero

### Instance methods inherited from module `Comparable(BigFloat)`

<(other : T) <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) >, >=(other : T) >=

### Instance methods inherited from module `Comparable(Number)`

<(other : T) <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) >, >=(other : T) >=

### Instance methods inherited from struct `Value`

==(other) ==, dup dup

### Instance methods inherited from class `Object`

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, class class, dup dup, hash hash, inspect(io : IO)
inspect inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json to_json, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ") to_pretty_json, to_s
to_s(io : IO) to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try, unsafe_as(type : T.class) forall T unsafe_as

### Constructor methods inherited from class `Object`

from_json(string_or_io, root : String) : self
from_json(string_or_io) : self from_json, from_yaml(string_or_io) : self from_yaml

## Constructor Detail

def self.new(numerator : Int, denominator : Int) #

Create a new `BigRational`.

If denominator is 0, this will raise an exception.

def self.new(num : Int) #

Creates a new `BigRational` with num as the numerator and 1 for denominator.

## Instance Method Detail

def *(other : BigRational) #
def *(other : Int) #
def +(other : BigRational) #
def +(other : Int) #
def -(other : BigRational) #
def -(other : Int) #
def - #
def /(other : Int) #
def /(other : BigRational) #
def <<(other : Int) #

Multiplies the rational by (2 ** other)

    BigRational.new(2, 3) << 2 # => 8/3

def <=>(other : BigRational) #
def <=>(other : Float) #
def <=>(other : Int) #
def >>(other : Int) #

Divides the rational by (2 ** other)

    BigRational.new(2, 3) >> 2 # => 1/6

def abs #
def clone #
def denominator #
def hash #
def inspect #
def inspect(io) #
def inv #

Returns a new `BigRational` as 1/r.

This will raise an exception if rational is 0.

def numerator #
def to_f #

Returns the `Float64` representing this rational.

def to_f32 #
def to_f64 #
def to_s(io : IO, base = 10) #
def to_s(base = 10) #

Returns the string representing this rational.

Optionally takes a radix base (2 through 36).

    r = BigRational.new(8243243, 562828882)
    r.to_s     # => "8243243/562828882"
    r.to_s(16) # => "7dc82b/218c1652"
    r.to_s(36) # => "4woiz/9b3djm"

def to_unsafe #