class Axiom::Types::Infinity

Represent an infinite number

Public Class Methods

<=>(other) click to toggle source

Test the number against infinity

@param [Numeric, Infinity] other

@return [0]

returned if the other object is infinity

@return [1]

returned if the other object is something other than infinity

@api private

# File lib/axiom/types/support/infinity.rb, line 19
def self.<=>(other)
  case other
  when ::BigDecimal                       then 1
  when ->(arg) { arg == number }          then 0
  when ::Numeric, inverse.singleton_class then 1
  end
end
coerce(other) click to toggle source

Coerce a number into an Infinity class for comparison

@param [::Numeric] other

@return [Array(Infinity, Infinity)]

@api private

# File lib/axiom/types/support/infinity.rb, line 34
def self.coerce(other)
  case other
  when ::BigDecimal then [inverse, self]
  when number       then [self,    self]
  when ::Numeric    then [inverse, self]
  else
    raise ::TypeError, "#{other.class} cannot be coerced"
  end
end
succ() click to toggle source

Return the next successive object, which is always self

@return [Class<Infinity>]

@api private

# File lib/axiom/types/support/infinity.rb, line 49
def self.succ
  self
end

Private Class Methods

inverse() click to toggle source

The inverse of infinity

@return [Class<NegativeInfinity>]

@api private

# File lib/axiom/types/support/infinity.rb, line 58
def self.inverse
  NegativeInfinity
end
number() click to toggle source

The numeric representation of infinity

@return [Float]

@api private

# File lib/axiom/types/support/infinity.rb, line 68
def self.number
  ::Float::INFINITY
end