2022-10-10 18:44:51 +02:00
|
|
|
|
|
|
|
def eps(base, n): # n = Anzahl Stellen der Mantisse
|
|
|
|
return 0.5 * (base ** (1-n))
|
|
|
|
|
|
|
|
|
2022-10-13 13:31:53 +02:00
|
|
|
def bitsMantiss(base):
|
2022-10-10 18:44:51 +02:00
|
|
|
last_x = 0
|
|
|
|
x = 1.5
|
2022-10-13 13:31:53 +02:00
|
|
|
n = 0
|
2022-10-10 18:44:51 +02:00
|
|
|
while x > 1:
|
|
|
|
last_x = x
|
|
|
|
x = x - (x - 1) / base
|
|
|
|
n = n + 1
|
|
|
|
return n, last_x
|
|
|
|
|
2022-10-13 13:31:53 +02:00
|
|
|
def largestNumber(bitsMantiss):
|
2022-10-10 18:44:51 +02:00
|
|
|
x = 0.0
|
2022-10-13 13:31:53 +02:00
|
|
|
for i in range(bitsMantiss):
|
2022-10-10 18:44:51 +02:00
|
|
|
x = x + 2 ** i
|
|
|
|
return x
|
|
|
|
|
|
|
|
def largestNumber_eps(eps, n):
|
|
|
|
return eps * 2**(2*n) - 1
|
|
|
|
|
|
|
|
|
2022-10-13 13:31:53 +02:00
|
|
|
bitsMan = bitsMantiss(2)
|
|
|
|
epsVal = eps(2, bitsMan[0])
|
|
|
|
largest = largestNumber(bitsMan[0])
|
|
|
|
largest_eps = largestNumber_eps(epsVal, bitsMan[0])
|
2022-10-10 18:44:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
print(f'eps: {epsVal}')
|
2022-10-13 13:31:53 +02:00
|
|
|
print(f'Bits Mantiss: {bitsMan[0]}')
|
|
|
|
print(f'Smallest Number 1 + eps > 1: {bitsMan[1]}')
|
2022-10-10 18:44:51 +02:00
|
|
|
print(f'largest Number 1 + qmax > qmax: {largest}')
|
|
|
|
print(f'largest Number 1 + qmax > qmax (calculated by eps: {largest_eps}')
|