diff --git a/HM1_Serie2.pdf b/HM1_Serie2.pdf index aeded75..d1f9eb8 100644 Binary files a/HM1_Serie2.pdf and b/HM1_Serie2.pdf differ diff --git a/Schenk_Brandenberger_S2_Aufg4.py b/Schenk_Brandenberger_S2_Aufg4.py index ecfe13e..bee30e5 100644 --- a/Schenk_Brandenberger_S2_Aufg4.py +++ b/Schenk_Brandenberger_S2_Aufg4.py @@ -1,8 +1,38 @@ -def maxPower(base): - x = 0.5 - power = 0 - while x > 0: - power = power + 1 - x = x / base - return power -print(maxPower(2)) \ No newline at end of file + +def eps(base, n): # n = Anzahl Stellen der Mantisse + return 0.5 * (base ** (1-n)) + + +def digitsMantiss(base): # -5*10^-17 + last_x = 0 + x = 1.5 + n = 1 + while x > 1: + last_x = x + x = x - (x - 1) / base + n = n + 1 + return n, last_x + +def largestNumber(digitsMantiss): + x = 0.0 + for i in range(digitsMantiss): + x = x + 2 ** i + return x + +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]) + + +print(f'eps: {epsVal}') +print(f'Digits Mantiss: {digMan[0]}') +print(f'Smallest Number 1 + eps > 1: {digMan[1]}') +print(f'largest Number 1 + qmax > qmax: {largest}') +print(f'largest Number 1 + qmax > qmax (calculated by eps: {largest_eps}') \ No newline at end of file