2015-04-08 19:32:56 +02:00
|
|
|
|
2016-12-30 17:39:49 +01:00
|
|
|
# Integer class for representing maths on Integers
|
2018-03-19 16:48:56 +01:00
|
|
|
# Integers are Objects, specifically DataObjects
|
2015-04-08 19:32:56 +02:00
|
|
|
# - they have fixed value
|
|
|
|
# - they are immutable
|
2018-03-13 08:00:51 +01:00
|
|
|
# (both by implementation, not design.
|
|
|
|
# Ie it would be possible to change the value, we just don't support that)
|
2015-04-08 19:32:56 +02:00
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
module Parfait
|
2018-03-31 18:12:06 +02:00
|
|
|
class Integer < Data4
|
2015-04-08 19:32:56 +02:00
|
|
|
|
2018-03-31 18:12:06 +02:00
|
|
|
def initialize(value , next_i = nil)
|
2018-03-31 12:58:08 +02:00
|
|
|
super()
|
2018-03-31 12:25:59 +02:00
|
|
|
@value = value
|
2018-03-31 19:21:27 +02:00
|
|
|
@next_integer = next_i
|
2018-03-31 12:25:59 +02:00
|
|
|
end
|
2018-03-31 19:21:27 +02:00
|
|
|
attr_reader :next_integer, :value
|
2018-03-31 12:25:59 +02:00
|
|
|
|
2018-03-31 18:12:06 +02:00
|
|
|
def self.integer_index
|
|
|
|
3 # 1 type, 2 next_i
|
|
|
|
end
|
2018-03-31 18:37:24 +02:00
|
|
|
|
|
|
|
def get_internal_word( index )
|
|
|
|
return super(index) unless index == Integer.integer_index
|
|
|
|
return @value
|
|
|
|
end
|
2015-05-11 17:55:49 +02:00
|
|
|
# :integer?, :odd?, :even?, :upto, :downto, :times, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor,
|
|
|
|
# :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize,
|
|
|
|
# :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,
|
|
|
|
# :real?, :zero?, :nonzero?, :step, :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase,
|
|
|
|
# :rectangular, :rect, :polar, :conjugate, :conj, :>, :>=, :<, :<=, :between?
|
|
|
|
#
|
|
|
|
# Numeric
|
|
|
|
# :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,
|
|
|
|
# :to_int, :real?, :integer?, :zero?, :nonzero?, :floor, :ceil, :round, :truncate, :step, :numerator, :denominator,
|
|
|
|
# :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, :conj,
|
|
|
|
# :>, :>=, :<, :<=, :between?
|
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
|
|
|
|
# adding other base classes in here for now:
|
2018-03-31 18:12:06 +02:00
|
|
|
class FalseClass < Data4
|
2018-03-31 12:47:02 +02:00
|
|
|
#FIXME: this is "just" for compilation
|
|
|
|
def initialize
|
2018-03-31 12:58:08 +02:00
|
|
|
super
|
2018-03-31 12:47:02 +02:00
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
end
|
2018-03-31 18:12:06 +02:00
|
|
|
class TrueClass < Data4
|
2018-03-31 12:47:02 +02:00
|
|
|
#FIXME: this is "just" for compilation
|
|
|
|
def initialize
|
2018-03-31 12:58:08 +02:00
|
|
|
super
|
2018-03-31 12:47:02 +02:00
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
end
|
2018-03-31 18:12:06 +02:00
|
|
|
class NilClass < Data4
|
2018-03-31 12:47:02 +02:00
|
|
|
#FIXME: this is "just" for compilation
|
|
|
|
def initialize
|
2018-03-31 12:58:08 +02:00
|
|
|
super
|
2018-03-31 12:47:02 +02:00
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
end
|
2015-04-08 19:32:56 +02:00
|
|
|
end
|