class Counting
Public Class Methods
new(a)
click to toggle source
# File lib/m500.rb, line 1242 def initialize(a) if (a.kind_of?(Counting)) @a = a.to_i elsif a.kind_of?(Integer) #a.kind_of?(Fixnum) or a.kind_of?(Bignum) @a = a else end end
new!(num)
click to toggle source
# File lib/m500.rb, line 1238 def Counting.new!(num) new(num) end
Private Class Methods
new(a)
click to toggle source
# File lib/m500.rb, line 786 def initialize(a) if (a.kind_of?(Integer) && a >= 1) #(a.kind_of?(Fixnum) && a >= 1) or (a.kind_of?(Bignum) && a >= 1) @a = a else emptySet end end
Public Instance Methods
%(a)
click to toggle source
# File lib/m500.rb, line 1316 def % (a) self.to_i%(a.to_i) end
*(a)
click to toggle source
# File lib/m500.rb, line 1276 def * (a) t = nil if a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural) or a.kind_of?(Integer) # or a.kind_of?(Bignum) or a.kind_of?(Fixnum) a < 0 ? emptySet : Counting(@a*a) elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass) naught elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass) infinity else x, y = a.coerce(self) y < 0 ? emptySet : Counting(x*y) end end
**(a)
click to toggle source
# File lib/m500.rb, line 1298 def ** (a) if a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural) or a.kind_of?(Integer) #a.kind_of?(Bignum) or a.kind_of?(Fixnum) Counting(self.to_i ** a.to_i) else x, y = a.coerce(self) Counting(x ** y) end end
+(a)
click to toggle source
# File lib/m500.rb, line 1250 def + (a) if a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural) or a.kind_of?(Integer) #a.kind_of?(Bignum) or a.kind_of?(Fixnum) Counting(@a+a) elsif a.kind_of?(Decimal) or a.kind_of?(Quotient) or a.kind_of?(Fraction) Counting(@a+a.to_N0) elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass) self elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass) infinity else x, y = a.coerce(self) Counting(x+y) end end
-(a)
click to toggle source
# File lib/m500.rb, line 1264 def - (a) if a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural) or a.kind_of?(Integer) #a.kind_of?(Bignum) or a.kind_of?(Fixnum) @a-a < 0 ? emptySet : Counting(@a-a) elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass) self elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass) infinity else x, y = a.coerce(self) x-y < 0 ? emptySet : Counting(x - y) end end
/(a)
click to toggle source
# File lib/m500.rb, line 1289 def / (a) if (a.kind_of?(Counting) or a.kind_of?(Natural)) and (self.to_i%(a.to_i) == 0) a < 0 ? emptySet : Counting(@a/ a) else #not divisable so will not be whole number return emptySet #y < 0 ? emptySet : Counting(x/y) #x, y = a.coerce(self) return emptySet end end
<=>(other)
click to toggle source
# File lib/m500.rb, line 1322 def <=> (other) unless other.kind_of?(Counting) then other = Counting.new!(other) end if @a > other return 1 elsif @a < other return -1 elsif @a == other return 0 end end
abs()
click to toggle source
# File lib/m500.rb, line 1319 def abs @a.to_i.abs end
coerce(other)
click to toggle source
# File lib/m500.rb, line 1332 def coerce(other) if Integer === other [other, @a] else Float === other return other, self.to_f end end
each() { |Counting(a+1)| ... }
click to toggle source
# File lib/m500.rb, line 1348 def each yield Counting(@a+1) end
factorial()
click to toggle source
# File lib/m500.rb, line 1309 def factorial if self == Counting(0) Counting(1) else self * Counting(self.to_i-1).factorial end end
factorial_1()
click to toggle source
# File lib/m500.rb, line 1306 def factorial_1 (Counting(1)..self).inject {|product, n| product * n } end
hash()
click to toggle source
# File lib/m500.rb, line 1386 def hash @a.hash end
inspect()
click to toggle source
# File lib/m500.rb, line 1383 def inspect sprintf("Counting(%s)", @a) end
next()
click to toggle source
# File lib/m500.rb, line 1339 def next self + Counting(1) end
succ()
click to toggle source
# File lib/m500.rb, line 1342 def succ self.next end
to_Dec()
click to toggle source
# File lib/m500.rb, line 1372 def to_Dec Decimal(@a) end
to_Frac()
click to toggle source
# File lib/m500.rb, line 1366 def to_Frac Fraction(@a,1) end
to_K()
click to toggle source
# File lib/m500.rb, line 1378 def to_K Kettenbruch(self.to_Frac) end
to_N()
click to toggle source
# File lib/m500.rb, line 1360 def to_N Natural(@a) end
to_Q()
click to toggle source
# File lib/m500.rb, line 1369 def to_Q Quotient(@a,1) end
to_R()
click to toggle source
# File lib/m500.rb, line 1381 def to_R end
to_Sig()
click to toggle source
# File lib/m500.rb, line 1375 def to_Sig Sigma(self.to_Q) end
to_Z()
click to toggle source
# File lib/m500.rb, line 1363 def to_Z Zahlen(@a) end
to_f()
click to toggle source
# File lib/m500.rb, line 1354 def to_f @a.to_f end
to_i()
click to toggle source
# File lib/m500.rb, line 1351 def to_i @a.to_i end
to_s()
click to toggle source
# File lib/m500.rb, line 1357 def to_s "Counting(#{@a})" end
to_sgml()
click to toggle source
# File lib/m500.rb, line 1235 def to_sgml "<mn #{sgml_id}class='counting'>#{@a}</mn>" end