updated Task 4
This commit is contained in:
parent
ca306c728b
commit
d2c1d957e8
|
@ -3,19 +3,19 @@ def eps(base, n): # n = Anzahl Stellen der Mantisse
|
|||
return 0.5 * (base ** (1-n))
|
||||
|
||||
|
||||
def digitsMantiss(base): # -5*10^-17
|
||||
def bitsMantiss(base):
|
||||
last_x = 0
|
||||
x = 1.5
|
||||
n = 1
|
||||
n = 0
|
||||
while x > 1:
|
||||
last_x = x
|
||||
x = x - (x - 1) / base
|
||||
n = n + 1
|
||||
return n, last_x
|
||||
|
||||
def largestNumber(digitsMantiss):
|
||||
def largestNumber(bitsMantiss):
|
||||
x = 0.0
|
||||
for i in range(digitsMantiss):
|
||||
for i in range(bitsMantiss):
|
||||
x = x + 2 ** i
|
||||
return x
|
||||
|
||||
|
@ -23,16 +23,14 @@ def largestNumber_eps(eps, n):
|
|||
return eps * 2**(2*n) - 1
|
||||
|
||||
|
||||
|
||||
|
||||
digMan = digitsMantiss(2)
|
||||
epsVal = eps(2, digMan[0])
|
||||
largest = largestNumber(digMan[0])
|
||||
largest_eps = largestNumber_eps(epsVal, digMan[0])
|
||||
bitsMan = bitsMantiss(2)
|
||||
epsVal = eps(2, bitsMan[0])
|
||||
largest = largestNumber(bitsMan[0])
|
||||
largest_eps = largestNumber_eps(epsVal, bitsMan[0])
|
||||
|
||||
|
||||
print(f'eps: {epsVal}')
|
||||
print(f'Digits Mantiss: {digMan[0]}')
|
||||
print(f'Smallest Number 1 + eps > 1: {digMan[1]}')
|
||||
print(f'Bits Mantiss: {bitsMan[0]}')
|
||||
print(f'Smallest Number 1 + eps > 1: {bitsMan[1]}')
|
||||
print(f'largest Number 1 + qmax > qmax: {largest}')
|
||||
print(f'largest Number 1 + qmax > qmax (calculated by eps: {largest_eps}')
|
Loading…
Reference in New Issue