Class: Zahlen

Inherits:
Counting show all
Includes:
SGML
Defined in:
lib/m500.rb

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



1316
1317
1318
1319
1320
1321
1322
1323
# File 'lib/m500.rb', line 1316

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



1312
1313
1314
# File 'lib/m500.rb', line 1312

def Zahlen.new!(num)
  new(num)
end

Instance Method Details

#%(a) ⇒ Object



1383
1384
1385
# File 'lib/m500.rb', line 1383

def % (a)
  self.to_i%(a.to_i)
end

#*(a) ⇒ Object



1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
# File 'lib/m500.rb', line 1352

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



1375
1376
1377
1378
1379
1380
1381
1382
# File 'lib/m500.rb', line 1375

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



1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
# File 'lib/m500.rb', line 1324

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



1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
# File 'lib/m500.rb', line 1338

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



1366
1367
1368
1369
1370
1371
1372
1373
1374
# File 'lib/m500.rb', line 1366

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



1414
1415
1416
# File 'lib/m500.rb', line 1414

def <=>(other)
  self.to_i <=> other.to_i
end

#absObject



1386
1387
1388
# File 'lib/m500.rb', line 1386

def abs
  @a.to_i.abs
end

#coerce(other) ⇒ Object



1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
# File 'lib/m500.rb', line 1398

def coerce(other)
#  if other.kind_of?(Float) then
#    other, @a
#  elsif other.kind_of?(Numeric)
#    return Zahlen.new!(other.to_i), self
#  else
#    other, @a 
#  end
  [other, @a]
end

#gcd(n) ⇒ Object



1389
1390
1391
1392
1393
1394
1395
1396
1397
# File 'lib/m500.rb', line 1389

def gcd(n)
  g = nil
  if @a>0 then
    g = Natural( @a).gcd(n)
  else
    g = Natural(-1* @a).gcd(n)
  end
  g
end

#inspectObject



1452
1453
1454
# File 'lib/m500.rb', line 1452

def inspect
  sprintf("Zahlen(%s)", @a.to_s)
end

#nextObject



1408
1409
1410
# File 'lib/m500.rb', line 1408

def next
  self + Zahlen(1)
end

#next_primeObject



1455
1456
1457
# File 'lib/m500.rb', line 1455

def next_prime
  emptySet
end

#succObject



1411
1412
1413
# File 'lib/m500.rb', line 1411

def succ
  self.next
end

#to_DecObject



1441
1442
1443
# File 'lib/m500.rb', line 1441

def to_Dec
  Decimal(@a,0,'0')
end

#to_fObject



1420
1421
1422
# File 'lib/m500.rb', line 1420

def to_f
  @a.to_f
end

#to_FracObject



1435
1436
1437
# File 'lib/m500.rb', line 1435

def to_Frac
  Fraction(@a,Quotient(0,1))
end

#to_iObject



1417
1418
1419
# File 'lib/m500.rb', line 1417

def to_i
  @a.to_i
end

#to_KObject



1447
1448
1449
# File 'lib/m500.rb', line 1447

def to_K
  Kettenbruch(self.to_Frac)
end

#to_NObject



1429
1430
1431
# File 'lib/m500.rb', line 1429

def to_N
  Natural(@a)
end

#to_QObject



1438
1439
1440
# File 'lib/m500.rb', line 1438

def to_Q
  Quotient(@a,1)
end

#to_RObject



1450
1451
# File 'lib/m500.rb', line 1450

def to_R
end

#to_sObject



1426
1427
1428
# File 'lib/m500.rb', line 1426

def to_s
  @a.to_s
end

#to_s!Object



1423
1424
1425
# File 'lib/m500.rb', line 1423

def to_s!
  "Zahlen(#{@a})"
end

#to_sgmlObject



1309
1310
1311
# File 'lib/m500.rb', line 1309

def to_sgml
  "<mn #{sgml_id}class='zahlen'>#{@a}</mn>"
end

#to_SigObject



1444
1445
1446
# File 'lib/m500.rb', line 1444

def to_Sig
  Sigma(self.to_Q)
end

#to_ZObject



1432
1433
1434
# File 'lib/m500.rb', line 1432

def to_Z
  Zahlen(@a)
end