Class: Counting
Direct Known Subclasses
Zahlen
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from SGML
#sgml_id, #tog_sgml_id
Methods inherited from Natural
#==, #div, #divmod, #gcd, #gcd2, #gcdlcm, #is_0?, #lcm, #next_prime
Methods inherited from Numeric
#irrational?, #rational?, #sgml_id, #to_N0
Constructor Details
#initialize(a) ⇒ Counting
Returns a new instance of Counting.
1157
1158
1159
1160
1161
1162
1163
1164
|
# File 'lib/m500.rb', line 1157
def initialize(a)
if (a.kind_of?(Counting))
@a = a.to_i
elsif a.kind_of?(Fixnum) or a.kind_of?(Bignum)
@a = a
else
end
end
|
Class Method Details
.new!(num) ⇒ Object
1153
1154
1155
|
# File 'lib/m500.rb', line 1153
def Counting.new!(num)
new(num)
end
|
Instance Method Details
#%(a) ⇒ Object
1230
1231
1232
|
# File 'lib/m500.rb', line 1230
def % (a)
self.to_i%(a.to_i)
end
|
#**(a) ⇒ Object
1212
1213
1214
1215
1216
1217
1218
1219
|
# File 'lib/m500.rb', line 1212
def ** (a)
if a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural) or 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) ⇒ Object
1204
1205
1206
1207
1208
1209
1210
1211
|
# File 'lib/m500.rb', line 1204
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
x, y = a.coerce(self)
y < 0 ? emptySet : Counting(x/y)
end
end
|
#<=>(other) ⇒ Object
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
|
# File 'lib/m500.rb', line 1236
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 ⇒ Object
1233
1234
1235
|
# File 'lib/m500.rb', line 1233
def abs
@a.to_i.abs
end
|
#coerce(other) ⇒ Object
1246
1247
1248
1249
1250
1251
1252
|
# File 'lib/m500.rb', line 1246
def coerce(other)
if Integer === other
[other, @a]
else Float === other
return other, self.to_f
end
end
|
#each {|Counting(@a+1)| ... } ⇒ Object
1262
1263
1264
|
# File 'lib/m500.rb', line 1262
def each
yield Counting(@a+1)
end
|
#factorial ⇒ Object
1223
1224
1225
1226
1227
1228
1229
|
# File 'lib/m500.rb', line 1223
def factorial
if self == Counting(0)
Counting(1)
else
self * Counting(self.to_i-1).factorial
end
end
|
#factorial_1 ⇒ Object
1220
1221
1222
|
# File 'lib/m500.rb', line 1220
def factorial_1
(Counting(1)..self).inject {|product, n| product * n }
end
|
#hash ⇒ Object
1303
1304
1305
|
# File 'lib/m500.rb', line 1303
def hash
@a.hash
end
|
#inspect ⇒ Object
1300
1301
1302
|
# File 'lib/m500.rb', line 1300
def inspect
sprintf("Counting(%s)", @a)
end
|
#next ⇒ Object
1253
1254
1255
|
# File 'lib/m500.rb', line 1253
def next
self + Counting(1)
end
|
#succ ⇒ Object
1256
1257
1258
|
# File 'lib/m500.rb', line 1256
def succ
self.next
end
|
#to_Dec ⇒ Object
1289
1290
1291
|
# File 'lib/m500.rb', line 1289
def to_Dec
Decimal(@a)
end
|
#to_f ⇒ Object
1268
1269
1270
|
# File 'lib/m500.rb', line 1268
def to_f
@a.to_f
end
|
#to_Frac ⇒ Object
1283
1284
1285
|
# File 'lib/m500.rb', line 1283
def to_Frac
Fraction(@a,1)
end
|
#to_i ⇒ Object
1265
1266
1267
|
# File 'lib/m500.rb', line 1265
def to_i
@a.to_i
end
|
#to_K ⇒ Object
1295
1296
1297
|
# File 'lib/m500.rb', line 1295
def to_K
Kettenbruch(self.to_Frac)
end
|
#to_N ⇒ Object
1277
1278
1279
|
# File 'lib/m500.rb', line 1277
def to_N
Natural(@a)
end
|
#to_Q ⇒ Object
1286
1287
1288
|
# File 'lib/m500.rb', line 1286
def to_Q
Quotient(@a,1)
end
|
#to_R ⇒ Object
1298
1299
|
# File 'lib/m500.rb', line 1298
def to_R
end
|
#to_s ⇒ Object
1274
1275
1276
|
# File 'lib/m500.rb', line 1274
def to_s
@a.to_s
end
|
#to_s! ⇒ Object
1271
1272
1273
|
# File 'lib/m500.rb', line 1271
def to_s!
"Counting(#{@a})"
end
|
#to_sgml ⇒ Object
1150
1151
1152
|
# File 'lib/m500.rb', line 1150
def to_sgml
"<mn #{sgml_id}class='counting'>#{@a}</mn>"
end
|
#to_Sig ⇒ Object
1292
1293
1294
|
# File 'lib/m500.rb', line 1292
def to_Sig
Sigma(self.to_Q)
end
|
#to_Z ⇒ Object
1280
1281
1282
|
# File 'lib/m500.rb', line 1280
def to_Z
Zahlen(@a)
end
|