Hong-Phuc Bui
2024-04-21 a748a17c7285910b32617850cb52d9a048bcbd46
add bsp while
2 files modified
3 files added
61 ■■■■■ changed files
README.md 4 ●●●● patch | view | raw | blame | history
python-grundlage/c/quake_iii_fisqrt.c 32 ●●●●● patch | view | raw | blame | history
python-grundlage/c/size_of_test.c 2 ●●● patch | view | raw | blame | history
python-grundlage/find-machinell-epsilon.py 13 ●●●●● patch | view | raw | blame | history
python-grundlage/sqrt-newton.py 10 ●●●●● patch | view | raw | blame | history
README.md
@@ -1,2 +1,6 @@
# Hier ist eine Sammlung von Beispiel-Projekts Sommersemester 2024
## python-grundlage
Das notwendigste Wissen über Python
python-grundlage/c/quake_iii_fisqrt.c
New file
@@ -0,0 +1,32 @@
/* 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;
}
python-grundlage/c/size_of_test.c
@@ -5,7 +5,7 @@
    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)
    {
python-grundlage/find-machinell-epsilon.py
New file
@@ -0,0 +1,13 @@
# 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}")
python-grundlage/sqrt-newton.py
New file
@@ -0,0 +1,10 @@
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}")