module

FixedDecimal::Value

Conversions to and from the arbitrary-precision types in big, which needs libgmp. Opt in with require "fixed_decimal/big".

Instance methods

&+(other : self) : self

Wrapping addition.

Source
&-(other : self) : self

Wrapping subtraction.

Source
*(other : self) : self

Multiplies, rounding half-to-even.

Source
*(other : Int) : self

Multiplies by an integer exactly.

Source
+(other : self) : self
Source
+(other : Int) : self
Source
-(other : self) : self
Source
-(other : Int) : self
Source
-

Negation. Raises OverflowError if the result is out of range.

Source
/(other : self) : self

Divides, rounding half-to-even. Raises DivisionByZeroError for a zero divisor.

Source
/(other : Int) : self

Divides, rounding half-to-even. Raises DivisionByZeroError for a zero divisor.

Source
<=>(other : FixedDecimal::Value) : Int32

Compares exact values, even across different types and fraction bits.

Source
<=>(other : Int) : Int32

Compares exact values, even across different types and fraction bits.

Source
<=>(other : Float) : Int32 | Nil

Compares exact values; nil if other is NaN.

Source
abs

The absolute value. Raises OverflowError for Fixed(N).min.

Source
ceil
Source
floor
Source
format(width : Int32 | Nil = nil, decimal : Int32 | Nil = nil, padding : Char = ' ') : String

Formats like sprintf("%*.*f", width, decimal, value).

  • width is the minimum field width; a negative width left-justifies.
  • decimal is the exact number of fraction digits, rounded half-to-even; nil means the shortest form, as in #to_s, and 0 omits the decimal point.
  • padding fills the field. A '0' goes between the sign and the digits, as with sprintf's 0 flag, and becomes a space when left-justifying.
Fixed(16).new("-3.25").format(8, 3, '0') # => "-003.250"
Source
format(io : IO, width : Int32 | Nil = nil, decimal : Int32 | Nil = nil, padding : Char = ' ') : Nil

Formats like sprintf("%*.*f", width, decimal, value).

  • width is the minimum field width; a negative width left-justifies.
  • decimal is the exact number of fraction digits, rounded half-to-even; nil means the shortest form, as in #to_s, and 0 omits the decimal point.
  • padding fills the field. A '0' goes between the sign and the digits, as with sprintf's 0 flag, and becomes a space when left-justifying.
Fixed(16).new("-3.25").format(8, 3, '0') # => "-003.250"
Source
format(io : IO, spec : String) : Nil

Formats using a sprintf-style spec: %[flags][width][.precision][f].

  • The leading % is optional.
  • Flags: - left-justifies, + always shows a sign, a space shows a space for non-negative values, 0 pads with zeros and # always shows the decimal point.
  • With the f (or F) conversion the precision defaults to 6, as in sprintf; without it the shortest form is used.

Raises ArgumentError for an invalid spec.

Fixed(16).new("2.5").format("%+08.2f") # => "+0002.50"
Fixed(16).new("2.5").format("-6")      # => "2.5   "
Source
format(spec : String) : String

Formats using a sprintf-style spec: %[flags][width][.precision][f].

  • The leading % is optional.
  • Flags: - left-justifies, + always shows a sign, a space shows a space for non-negative values, 0 pads with zeros and # always shows the decimal point.
  • With the f (or F) conversion the precision defaults to 6, as in sprintf; without it the shortest form is used.

Raises ArgumentError for an invalid spec.

Fixed(16).new("2.5").format("%+08.2f") # => "+0002.50"
Fixed(16).new("2.5").format("-6")      # => "2.5   "
Source
fraction_bits

The number of fraction bits.

Source
hash(hasher)

Equal values hash equally, including equal Int and Float values.

Source
inspect(io : IO) : Nil

Same as #to_s.

Source
integer?

True when there is no fraction part.

Source
negative?
Source
positive?
Source
reverse_add(other : Int) : self

other + self for Int#+.

:nodoc:

Source
reverse_divide(other : Int) : self

other / self for Int#/.

:nodoc:

Source
reverse_subtract(other : Int) : self

other - self for Int#-.

:nodoc:

Source
round(mode : Number::RoundingMode = :ties_even) : self

Rounds to an integral value using mode. Raises OverflowError if the result is out of range.

Source
sign

-1, 0 or 1.

Source
to_big_d

The exact value.

Source
to_big_f

The exact value; every value fits in 128 bits of precision.

Source
to_big_i

Truncates toward zero.

Source
to_big_r

The exact value.

Source
to_f

Same as #to_f64.

Source
to_f!

Same as #to_f64!.

Source
to_f32

The nearest Float32, rounding half-to-even. Raises OverflowError if it rounds beyond Float32::MAX.

Source
to_f32!

Like #to_f32, but returns infinity when out of range.

Source
to_f32?

Like #to_f32, but returns nil when out of range.

Source
to_f64

The nearest Float64, rounding half-to-even. Every value is in range.

Source
to_f64!

The nearest Float64, rounding half-to-even. Every value is in range.

Source
to_f64?

The nearest Float64, rounding half-to-even. Every value is in range.

Source
to_f?

Same as #to_f64?.

Source
to_i

Same as #to_i32.

Source
to_i!

Same as #to_i32!.

Source
to_i128

Truncates toward zero and converts to Int128. Raises OverflowError if the integer part is out of range.

Source
to_i128!

Truncates toward zero and converts to Int128, wrapping around on overflow like Int#to_i128!.

Source
to_i128?

Truncates toward zero and converts to Int128, or returns nil if the integer part is out of range.

Source
to_i16

Truncates toward zero and converts to Int16. Raises OverflowError if the integer part is out of range.

Source
to_i16!

Truncates toward zero and converts to Int16, wrapping around on overflow like Int#to_i16!.

Source
to_i16?

Truncates toward zero and converts to Int16, or returns nil if the integer part is out of range.

Source
to_i32

Truncates toward zero and converts to Int32. Raises OverflowError if the integer part is out of range.

Source
to_i32!

Truncates toward zero and converts to Int32, wrapping around on overflow like Int#to_i32!.

Source
to_i32?

Truncates toward zero and converts to Int32, or returns nil if the integer part is out of range.

Source
to_i64

Truncates toward zero and converts to Int64. Raises OverflowError if the integer part is out of range.

Source
to_i64!

Truncates toward zero and converts to Int64, wrapping around on overflow like Int#to_i64!.

Source
to_i64?

Truncates toward zero and converts to Int64, or returns nil if the integer part is out of range.

Source
to_i8

Truncates toward zero and converts to Int8. Raises OverflowError if the integer part is out of range.

Source
to_i8!

Truncates toward zero and converts to Int8, wrapping around on overflow like Int#to_i8!.

Source
to_i8?

Truncates toward zero and converts to Int8, or returns nil if the integer part is out of range.

Source
to_i?

Same as #to_i32?.

Source
to_s(io : IO) : Nil

Writes the shortest decimal representation that parses back to exactly this value. It always has a fraction digit ("1.0") unless there are no fraction bits ("1").

Source
to_u

Same as #to_u32.

Source
to_u!

Same as #to_u32!.

Source
to_u128

Truncates toward zero and converts to UInt128. Raises OverflowError if the integer part is out of range.

Source
to_u128!

Truncates toward zero and converts to UInt128, wrapping around on overflow like Int#to_u128!.

Source
to_u128?

Truncates toward zero and converts to UInt128, or returns nil if the integer part is out of range.

Source
to_u16

Truncates toward zero and converts to UInt16. Raises OverflowError if the integer part is out of range.

Source
to_u16!

Truncates toward zero and converts to UInt16, wrapping around on overflow like Int#to_u16!.

Source
to_u16?

Truncates toward zero and converts to UInt16, or returns nil if the integer part is out of range.

Source
to_u32

Truncates toward zero and converts to UInt32. Raises OverflowError if the integer part is out of range.

Source
to_u32!

Truncates toward zero and converts to UInt32, wrapping around on overflow like Int#to_u32!.

Source
to_u32?

Truncates toward zero and converts to UInt32, or returns nil if the integer part is out of range.

Source
to_u64

Truncates toward zero and converts to UInt64. Raises OverflowError if the integer part is out of range.

Source
to_u64!

Truncates toward zero and converts to UInt64, wrapping around on overflow like Int#to_u64!.

Source
to_u64?

Truncates toward zero and converts to UInt64, or returns nil if the integer part is out of range.

Source
to_u8

Truncates toward zero and converts to UInt8. Raises OverflowError if the integer part is out of range.

Source
to_u8!

Truncates toward zero and converts to UInt8, wrapping around on overflow like Int#to_u8!.

Source
to_u8?

Truncates toward zero and converts to UInt8, or returns nil if the integer part is out of range.

Source
to_u?

Same as #to_u32?.

Source
trunc
Source
zero?
Source