2 files modified
3 files added
| | |
| | | # Hier ist eine Sammlung von Beispiel-Projekts Sommersemester 2024 |
| | | |
| | | |
| | | ## python-grundlage |
| | | |
| | | Das notwendigste Wissen über Python |
New file |
| | |
| | | /* explain https://www.youtube.com/watch?v=p8u_k2LIZyo */ |
| | | |
| | | #include <stdio.h> |
| | | |
| | | float Q_rsqrt(float number) |
| | | { |
| | | long i; |
| | | float x2, y; |
| | | const float threehalfs = 1.5F; |
| | | |
| | | x2 = number*0.5F; |
| | | y = number; |
| | | i = *(long *) &y; |
| | | i = 0x5f3759df - (i >> 1); |
| | | printf("i = %lu\n", i); |
| | | y = *( float *) &i; |
| | | printf("y = %f\n", y); |
| | | y = y * (threehalfs - (x2*y*y)); |
| | | |
| | | return y; |
| | | } |
| | | |
| | | int main() |
| | | { |
| | | float n = 5.0; |
| | | float f = Q_rsqrt(n); |
| | | printf("1/sqrt(%f) = %f", n, f); |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | const unsigned int max = 4294967295; |
| | | const unsigned int max_as_negativ = -1; |
| | | printf("%d\n", max); // expected output: -1 |
| | | printf("%u\n", max); |
| | | printf("%u\n", max); // expected output: 4294967295 (32 bits) |
| | | bool same = max == max_as_negativ; |
| | | if(same) |
| | | { |
New file |
| | |
| | | # Credit: https://stackoverflow.com/a/57579379 |
| | | |
| | | import sys |
| | | |
| | | eps = 1.0 |
| | | while eps + 1 > 1: |
| | | eps /= 2 |
| | | eps *= 2 |
| | | sys_eps = sys.float_info.epsilon |
| | | print(f"The calculated epsilon: {eps}") |
| | | print(f" The system epsilon: {sys_eps}") |
| | | |
| | | |
New file |
| | |
| | | import sys |
| | | |
| | | n = float(sys.argv[1]) |
| | | EPSILON = sys.float_info.epsilon |
| | | |
| | | t = n |
| | | while abs(t - n/t) > (EPSILON*t): |
| | | t = (n / t + t) / 2 |
| | | |
| | | print(f"sqrt({n}) ~= {t}") |