1# date.rb: Written by Tadayoshi Funaba 1998-2011
2
3require 'date_core'
4require 'date/format'
5
6class Date
7
8  class Infinity < Numeric # :nodoc:
9
10    include Comparable
11
12    def initialize(d=1) @d = d <=> 0 end
13
14    def d() @d end
15
16    protected :d
17
18    def zero? () false end
19    def finite? () false end
20    def infinite? () d.nonzero? end
21    def nan? () d.zero? end
22
23    def abs() self.class.new end
24
25    def -@ () self.class.new(-d) end
26    def +@ () self.class.new(+d) end
27
28    def <=> (other)
29      case other
30      when Infinity; return d <=> other.d
31      when Numeric; return d
32      else
33	begin
34	  l, r = other.coerce(self)
35	  return l <=> r
36	rescue NoMethodError
37	end
38      end
39      nil
40    end
41
42    def coerce(other)
43      case other
44      when Numeric; return -d, d
45      else
46	super
47      end
48    end
49
50    def to_f
51      return 0 if @d == 0
52      if @d > 0
53	Float::INFINITY
54      else
55	-Float::INFINITY
56      end
57    end
58
59  end
60
61end
62