struct FP::FixedPoint(Underlying, Scale)

Overview

Some helper conversions to fp32 & fp64

Defined in:

fixedpoint.cr
impl.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(val : self) #

[View source]
def self.new(val : Number) #

[View source]
def self.new #

[View source]
def self.zero : self #

[View source]

Class Method Detail

def self.new_from_underlying(val : Underlying) #

[View source]

Instance Method Detail

def %(other : self) : self #

[View source]
def %(other : Number) : self #

[View source]
def *(other : self) : self #

[View source]
def *(other : Number) : self #

[View source]
def **(other : self) : self #

[View source]
def **(other : Number) : self #

[View source]
def +(other : self) : self #

[View source]
def +(other : Number) : self #

[View source]
def -(other : self) : self #

[View source]
def -(other : Number) : self #

[View source]
def - : self #

[View source]
def /(other : self) : self #

[View source]
def /(other : Number) : self #

[View source]
def <=>(other : FixedPoint) : Int32 #
Description copied from module Comparable(Number)

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]
def <=>(other : Float) : Int32 | Nil #
Description copied from module Comparable(Number)

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]
def <=>(other : Int) : Int32 #
Description copied from module Comparable(Number)

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]
def ceil : self #

[View source]
def floor : self #

[View source]
def hash(hasher) #
Description copied from class Object

Appends this object's value to hasher, and returns the modified hasher.

Usually the macro def_hash can be used to generate this method. Otherwise, invoke #hash(hasher) on each object's instance variables to accumulate the result:

def hash(hasher)
  hasher = @some_ivar.hash(hasher)
  hasher = @some_other_ivar.hash(hasher)
  hasher
end

[View source]
def modulo(other) : self #

[View source]
def remainder(other) : self #

[View source]
def round_away : self #

[View source]
def round_even : self #

[View source]
def to_f : Float64 #

[View source]
def to_f32 : Float32 #

[View source]
def to_f64 : Float64 #

[View source]
def to_fp32 : FixedPoint32 #

[View source]
def to_fp64 : FixedPoint64 #

[View source]
def to_i : Int32 #

[View source]
def to_i32 : Int32 #

[View source]
def to_i64 : Int64 #

[View source]
def to_s(io : IO) : Nil #
Description copied from class Object

Prints a nicely readable and concise string representation of this object, typically intended for users, to io.

This method is called when an object is interpolated in a string literal:

"foo #{bar} baz" # calls bar.to_io with the builder for this string

IO#<< calls this method to append an object to itself:

io << bar # calls bar.to_s(io)

Thus implementations must not interpolate self in a string literal or call io << self which both would lead to an endless loop.

Also see #inspect(IO).


[View source]
def trunc : self #

[View source]