Class: Zahlen
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from SGML
#sgml_id, #tog_sgml_id
Methods inherited from Counting
#each, #factorial, #factorial_1, #hash
Methods inherited from Natural
#==, #div, #divmod, #gcd2, #gcdlcm, #hash, #is_0?, #lcm
Methods inherited from Numeric
#irrational?, #rational?, #sgml_id, #to_N0
Constructor Details
#initialize(a) ⇒ Zahlen
Returns a new instance of Zahlen.
1386
1387
1388
1389
1390
1391
1392
1393
|
# File 'lib/m500.rb', line 1386
def initialize(a)
if (a.kind_of?(Zahlen))
@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
1382
1383
1384
|
# File 'lib/m500.rb', line 1382
def Zahlen.new!(num)
new(num)
end
|
Instance Method Details
#%(a) ⇒ Object
1453
1454
1455
|
# File 'lib/m500.rb', line 1453
def % (a)
self.to_i%(a.to_i)
end
|
#*(a) ⇒ Object
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
|
# File 'lib/m500.rb', line 1422
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)
Zahlen(self.to_i * a.to_i)
elsif a.kind_of?(Quotient) or a.kind_of?(Fraction)
a * Quotient(@a,1)
elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass) or a.nil?
naught
elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass)
infinity
else
x , y = a.coerce(self)
Zahlen(x * y)
end
end
|
#**(a) ⇒ Object
1445
1446
1447
1448
1449
1450
1451
1452
|
# File 'lib/m500.rb', line 1445
def ** (a)
if a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural)
Zahlen(self.to_i ** a.to_i)
else
x, y = a.coerce(self)
Zahlen(x ** y)
end
end
|
#+(a) ⇒ Object
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
|
# File 'lib/m500.rb', line 1394
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)
Zahlen(self.to_i + a.to_i)
elsif a.kind_of?(Quotient) or a.kind_of?(Fraction)
a + Quotient(@a,1)
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
end
end
|
#-(a) ⇒ Object
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
|
# File 'lib/m500.rb', line 1408
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)
Zahlen(self.to_i - a.to_i)
elsif a.kind_of?(Quotient) or a.kind_of?(Fraction)
a - Quotient(@a,1)
elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass)
self
elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass)
infinity*(-1)
else
x, y = a.coerce(self)
Zahlen(x - y)
end
end
|
#/(a) ⇒ Object
1436
1437
1438
1439
1440
1441
1442
1443
1444
|
# File 'lib/m500.rb', line 1436
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)) and self.to_i%(a.to_i) == 0
Zahlen(self.to_i / a.to_i)
elsif a.kind_of?(Quotient) or a.kind_of?(Fraction)
self * Quotient(a.to_Q.denominator,a.to_Q.numerator)
else
emptySet
end
end
|
#<=>(other) ⇒ Object
1484
1485
1486
|
# File 'lib/m500.rb', line 1484
def <=>(other)
self.to_i <=> other.to_i
end
|
#abs ⇒ Object
1456
1457
1458
|
# File 'lib/m500.rb', line 1456
def abs
@a.to_i.abs
end
|
#coerce(other) ⇒ Object
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
|
# File 'lib/m500.rb', line 1468
def coerce(other)
[other, @a]
end
|
#gcd(n) ⇒ Object
1459
1460
1461
1462
1463
1464
1465
1466
1467
|
# File 'lib/m500.rb', line 1459
def gcd(n)
g = nil
if @a>0 then
g = Natural( @a).gcd(n)
else
g = Natural(-1* @a).gcd(n)
end
g
end
|
#inspect ⇒ Object
1522
1523
1524
|
# File 'lib/m500.rb', line 1522
def inspect
sprintf("Zahlen(%s)", @a.to_s)
end
|
#next ⇒ Object
1478
1479
1480
|
# File 'lib/m500.rb', line 1478
def next
self + Zahlen(1)
end
|
#next_prime ⇒ Object
1525
1526
1527
|
# File 'lib/m500.rb', line 1525
def next_prime
emptySet
end
|
#succ ⇒ Object
1481
1482
1483
|
# File 'lib/m500.rb', line 1481
def succ
self.next
end
|
#to_Dec ⇒ Object
1511
1512
1513
|
# File 'lib/m500.rb', line 1511
def to_Dec
Decimal(@a,0,'0')
end
|
#to_f ⇒ Object
1490
1491
1492
|
# File 'lib/m500.rb', line 1490
def to_f
@a.to_f
end
|
#to_Frac ⇒ Object
1505
1506
1507
|
# File 'lib/m500.rb', line 1505
def to_Frac
Fraction(@a,Quotient(0,1))
end
|
#to_i ⇒ Object
1487
1488
1489
|
# File 'lib/m500.rb', line 1487
def to_i
@a.to_i
end
|
#to_K ⇒ Object
1517
1518
1519
|
# File 'lib/m500.rb', line 1517
def to_K
Kettenbruch(self.to_Frac)
end
|
#to_N ⇒ Object
1499
1500
1501
|
# File 'lib/m500.rb', line 1499
def to_N
Natural(@a)
end
|
#to_Q ⇒ Object
1508
1509
1510
|
# File 'lib/m500.rb', line 1508
def to_Q
Quotient(@a,1)
end
|
#to_R ⇒ Object
1520
1521
|
# File 'lib/m500.rb', line 1520
def to_R
end
|
#to_s ⇒ Object
1496
1497
1498
|
# File 'lib/m500.rb', line 1496
def to_s
@a.to_s
end
|
#to_s! ⇒ Object
1493
1494
1495
|
# File 'lib/m500.rb', line 1493
def to_s!
"Zahlen(#{@a})"
end
|
#to_sgml ⇒ Object
1379
1380
1381
|
# File 'lib/m500.rb', line 1379
def to_sgml
"<mn #{sgml_id}class='zahlen'>#{@a}</mn>"
end
|
#to_Sig ⇒ Object
1514
1515
1516
|
# File 'lib/m500.rb', line 1514
def to_Sig
Sigma(self.to_Q)
end
|
#to_Z ⇒ Object
1502
1503
1504
|
# File 'lib/m500.rb', line 1502
def to_Z
Zahlen(@a)
end
|