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.
1227
1228
1229
1230
1231
1232
1233
1234
|
# File 'lib/m500.rb', line 1227
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
1223
1224
1225
|
# File 'lib/m500.rb', line 1223
def Counting.new!(num)
new(num)
end
|
Instance Method Details
#%(a) ⇒ Object
1300
1301
1302
|
# File 'lib/m500.rb', line 1300
def % (a)
self.to_i%(a.to_i)
end
|
#**(a) ⇒ Object
1282
1283
1284
1285
1286
1287
1288
1289
|
# File 'lib/m500.rb', line 1282
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
1274
1275
1276
1277
1278
1279
1280
1281
|
# File 'lib/m500.rb', line 1274
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
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
|
# File 'lib/m500.rb', line 1306
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
1303
1304
1305
|
# File 'lib/m500.rb', line 1303
def abs
@a.to_i.abs
end
|
#coerce(other) ⇒ Object
1316
1317
1318
1319
1320
1321
1322
|
# File 'lib/m500.rb', line 1316
def coerce(other)
if Integer === other
[other, @a]
else Float === other
return other, self.to_f
end
end
|
#each {|Counting(@a+1)| ... } ⇒ Object
1332
1333
1334
|
# File 'lib/m500.rb', line 1332
def each
yield Counting(@a+1)
end
|
#factorial ⇒ Object
1293
1294
1295
1296
1297
1298
1299
|
# File 'lib/m500.rb', line 1293
def factorial
if self == Counting(0)
Counting(1)
else
self * Counting(self.to_i-1).factorial
end
end
|
#factorial_1 ⇒ Object
1290
1291
1292
|
# File 'lib/m500.rb', line 1290
def factorial_1
(Counting(1)..self).inject {|product, n| product * n }
end
|
#hash ⇒ Object
1373
1374
1375
|
# File 'lib/m500.rb', line 1373
def hash
@a.hash
end
|
#inspect ⇒ Object
1370
1371
1372
|
# File 'lib/m500.rb', line 1370
def inspect
sprintf("Counting(%s)", @a)
end
|
#next ⇒ Object
1323
1324
1325
|
# File 'lib/m500.rb', line 1323
def next
self + Counting(1)
end
|
#succ ⇒ Object
1326
1327
1328
|
# File 'lib/m500.rb', line 1326
def succ
self.next
end
|
#to_Dec ⇒ Object
1359
1360
1361
|
# File 'lib/m500.rb', line 1359
def to_Dec
Decimal(@a)
end
|
#to_f ⇒ Object
1338
1339
1340
|
# File 'lib/m500.rb', line 1338
def to_f
@a.to_f
end
|
#to_Frac ⇒ Object
1353
1354
1355
|
# File 'lib/m500.rb', line 1353
def to_Frac
Fraction(@a,1)
end
|
#to_i ⇒ Object
1335
1336
1337
|
# File 'lib/m500.rb', line 1335
def to_i
@a.to_i
end
|
#to_K ⇒ Object
1365
1366
1367
|
# File 'lib/m500.rb', line 1365
def to_K
Kettenbruch(self.to_Frac)
end
|
#to_N ⇒ Object
1347
1348
1349
|
# File 'lib/m500.rb', line 1347
def to_N
Natural(@a)
end
|
#to_Q ⇒ Object
1356
1357
1358
|
# File 'lib/m500.rb', line 1356
def to_Q
Quotient(@a,1)
end
|
#to_R ⇒ Object
1368
1369
|
# File 'lib/m500.rb', line 1368
def to_R
end
|
#to_s ⇒ Object
1344
1345
1346
|
# File 'lib/m500.rb', line 1344
def to_s
@a.to_s
end
|
#to_s! ⇒ Object
1341
1342
1343
|
# File 'lib/m500.rb', line 1341
def to_s!
"Counting(#{@a})"
end
|
#to_sgml ⇒ Object
1220
1221
1222
|
# File 'lib/m500.rb', line 1220
def to_sgml
"<mn #{sgml_id}class='counting'>#{@a}</mn>"
end
|
#to_Sig ⇒ Object
1362
1363
1364
|
# File 'lib/m500.rb', line 1362
def to_Sig
Sigma(self.to_Q)
end
|
#to_Z ⇒ Object
1350
1351
1352
|
# File 'lib/m500.rb', line 1350
def to_Z
Zahlen(@a)
end
|