Загрузить файлы в «works/SysProg/ПР 2»

This commit is contained in:
2026-11-25 16:39:18 +00:00
parent dc1ec447bd
commit 9cdddc46b0
5 changed files with 71 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdint.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 );
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) );
return y;
}
float Q_rsqrt_safe(float number) {
uint32_t i;
float y = number;
const float threehalfs = 1.5F;
float x2 = number * 0.5F;
union { float f; uint32_t i; } converter;
converter.f = y;
i = converter.i;
i = 0x5f3759df - (i >> 1);
converter.i = i;
y = converter.f;
y = y * (threehalfs - (x2 * y * y));
return y;
}
int main() {
float x = 4.0f;
printf("1/sqrt(4.0) = %f\n", Q_rsqrt_safe(x)); // Ожидаем 0.5
return 0;
}