#-- # Infinity # # Copyright (c) 2004,2005 Thomas Sawyer # # Ruby License # # This module is free software. You may use, modify, and/or redistribute this # software under the same terms as Ruby. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. # # # ========================================================================== # Revision History :: # -------------------------------------------------------------------------- # 04.05.01 Trans * Minor modifications to documentation. # ========================================================================== # # :NOTE: Plan to update the interface a bit. # #++ #:title: Infinity # # A full featured Infinity class, supporting aleph levels and signed # direction. Inifinty is a multiton based on the aleph and direction # values. The conastant INFINITY is provided as the common case with # aleph=0 and direction=+1 (positive). # # == Usage # # +INFINITY < 1 #=> false # -INFINITY < 1 #=> true # # a0 = Infinity[0] # a1 = Infinity[1] # # a0 < a1 #=> true # # = Author(s) # # * Thomas Sawyer # require 'mega/multiton' class Infinity < Numeric include Multiton def self.[](a) self.new(a) end attr_reader :aleph, :direction def initialize(aleph=0, direction=1) @aleph = aleph @direction = direction end def -@ self.class.instance(@aleph, @direction * -1) end def to_f (1.0/0) * @direction end def times loop do yield end end def <=>(x) return (x.kind_of?(Infinity) ? (@aleph <=> x.aleph) : @direction) end def to_s %Q{#{ '-' if @direction == -1 }Infinity[#{@aleph}]} end end # constant (for aleph=0) INFINITY = Infinity.instance