Skip to content

struct BigFloat
inherits Float

A BigFloat can represent arbitrarily large floats.

It is implemented under the hood with GMP.

Included modules

Comparable Comparable Comparable

Class methods

.default_precision

View source

.default_precision=(prec : Int)

View source

.new(num : Float, precision : Int)

View source

.new(str : String)

View source

.new(num : BigInt)

View source

.new(num : BigRational)

View source

.new(num : BigFloat)

View source

.new(num : Int8 | Int16 | Int32)

View source

.new(num : UInt8 | UInt16 | UInt32)

View source

.new(num : Int64)

View source

.new(num : UInt64)

View source

.new(num : Number)

View source

.new(mpf : LibGMP::MPF)

View source

Methods

#*(other : Number)

View source

#**(other : Int)

View source

#+(other : Number)

View source

#-(other : Number)

View source

#/(other : Int8) : BigFloat

View source

#/(other : Float64) : BigFloat

View source

#/(other : Float32) : BigFloat

View source

#/(other : UInt128) : BigFloat

View source

#/(other : Int128) : BigFloat

View source

#/(other : Int64) : BigFloat

View source

#/(other : Int32) : BigFloat

View source

#/(other : Int16) : BigFloat

View source

#/(other : UInt8 | UInt16 | UInt32 | UInt64)

View source

#/(other : BigInt) : BigFloat

View source

#/(other : BigFloat)

View source

#<=>(other : Number)

View source

#<=>(other : Float32 | Float64)

The comparison operator. Returns 0 if the two objects are equal, a negative number if this object is considered less than other, a positive number if this object is considered greater than other, or nil if the two objects are not comparable.

Subclasses define this method to provide class-specific ordering.

The comparison operator is usually used to sort values:

# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]

# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
View source

#<=>(other : BigInt)

View source

#<=>(other : BigFloat)

The comparison operator. Returns 0 if the two objects are equal, a negative number if this object is considered less than other, a positive number if this object is considered greater than other, or nil if the two objects are not comparable.

Subclasses define this method to provide class-specific ordering.

The comparison operator is usually used to sort values:

# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]

# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
View source

#abs

Returns the absolute value of this number.

123.abs  # => 123
-123.abs # => 123
View source

#ceil

View source

#clone

View source

#fdiv(other : Number::Primitive) : self

View source

#floor

View source

#hash(hasher)

Todo

improve this

View source

#to_big_f

View source

#to_big_i

Returns a BigInt representing this float (rounded using floor).

require "big"

1212341515125412412412421.0.to_big_i

View source

#to_f

View source

#to_f!

View source

#to_f32

View source

#to_f32!

View source

#to_f64

View source

#to_f64!

View source

#to_i

View source

#to_i!

View source

#to_i16

View source

#to_i16!

View source

#to_i32

View source

#to_i32!

View source

#to_i64

View source

#to_i64!

View source

#to_i8

View source

#to_i8!

View source

#to_s(io : IO) : Nil

Appends a String representation of this object to the given IO object.

An object must never append itself to the io argument, as this will in turn call to_s(io) on it.

View source

#to_u

View source

#to_u!

View source

#to_u16

View source

#to_u16!

View source

#to_u32

View source

#to_u32!

View source

#to_u64

View source

#to_u64!

View source

#to_u8

View source

#to_u8!

View source

#to_unsafe

View source

#trunc

View source