anyone know of a way to get at infinite times (if they exist) as one can for
Floats?
eg.
irb(main):001:0> 1.0/0
=> Infinity
but for Time objects.
-a
···
–
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
anyone know of a way to get at infinite times (if they exist) as one can for
Floats?
Unfortunately, Time is a limited resource. We cannot have times
further than 2038-01-19 on most platforms.
–
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
thanks, this is exactly what i have done. i would really like to see this
sort of thing built into the Time class, as Float::Infinity has been built
into the Float class.
-a
···
On Fri, 21 Mar 2003, Robert Klemme wrote:
Maybe this approach helps:
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
looks promising. however, can anyone explain why this approach to
implementing the comparisions does not work???
class Time
INF = INFINITY = 1.0 / 0
NINF = NEGATIVE_INFINITY = -1.0 / 0
EPOCH = Time.at(0)
class << INFINITY
include Comparable
def <=> o;self.id == o.id ? 0 : 1;end
end
class << NEGATIVE_INFINITY
include Comparable
def <=> o;self.id == o.id ? 0 : -1;end
end
class Time
NEGATIVE_INFINITY = -1.0 / 0
INFINITY = 1.0 / 0
EPOCH = 0
end
–
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
----CUT----
class Time
INF = INFINITY = 1.0 / 0
NINF = NEGATIVE_INFINITY = -1.0 / 0
EPOCH = Time.at(0)
class << INFINITY
include Comparable
def <=> o;id == o.id ? 0 : 1;end
end
class << NEGATIVE_INFINITY
include Comparable
def <=> o;self.id == o.id ? 0 : -1;end
end
def coerce(x)
case x
when Float
return [x, to_f]
when Integer
return [x, to_i]
else
super
end
end
objects.map do |a|
puts ‘========’
objects.map do |b|
puts “\t--------”
%w(<=> <= >= < > ==).map do |op|
display “#{a} #{op} #{b}”
end
end
end
----CUT----
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
No, you need to define it because it doesn’t exist.
Float#> doesn’t call <=> due to performance.
but
class << INF
include Comparable
…
end
should create a ‘>’ correct?
Currently, it doesn’t because of performance cost.
class << INFINITY
include Comparable
def <=> o;id == o.id ? 0 : 1;end
end
class << NEGATIVE_INFINITY
include Comparable
def <=> o;self.id == o.id ? 0 : -1;end
end
I guess these singletons are unnecessary, since Float already
includes Comparable and infinities return correct comparison.
···
At Sat, 22 Mar 2003 05:04:59 +0900, ahoward wrote: