diff --git a/works/SysProg/ПР 2/Задание 1 вывод.PNG b/works/SysProg/ПР 2/Задание 1 вывод.PNG new file mode 100644 index 0000000..1fa38cb Binary files /dev/null and b/works/SysProg/ПР 2/Задание 1 вывод.PNG differ diff --git a/works/SysProg/ПР 2/Задание 2 вывод.PNG b/works/SysProg/ПР 2/Задание 2 вывод.PNG new file mode 100644 index 0000000..9ef4665 Binary files /dev/null and b/works/SysProg/ПР 2/Задание 2 вывод.PNG differ diff --git a/works/SysProg/ПР 2/Задание 2.c b/works/SysProg/ПР 2/Задание 2.c new file mode 100644 index 0000000..d197cab --- /dev/null +++ b/works/SysProg/ПР 2/Задание 2.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +int is_nan_custom(float f) { + uint32_t bits; + memcpy(&bits, &f, sizeof(float)); + + uint32_t exp = (bits >> 23) & 0xFF; + uint32_t mantissa = bits & 0x7FFFFF; + + return (exp == 0xFF) && (mantissa != 0); +} + +int main() { + float a = 0.0f / 0.0f; + float b = 1.0f / 0.0f; + float c = 3.14f; + + printf("0.0/0.0 is NaN: %d\n", is_nan_custom(a)); // 1 (true) + printf("1.0/0.0 is NaN: %d\n", is_nan_custom(b)); // 0 (false) + printf("3.14 is NaN: %d\n", is_nan_custom(c)); // 0 (false) + + return 0; +} \ No newline at end of file diff --git a/works/SysProg/ПР 2/Задание 3 вывод.PNG b/works/SysProg/ПР 2/Задание 3 вывод.PNG new file mode 100644 index 0000000..3f06554 Binary files /dev/null and b/works/SysProg/ПР 2/Задание 3 вывод.PNG differ diff --git a/works/SysProg/ПР 2/Задание 3.c b/works/SysProg/ПР 2/Задание 3.c new file mode 100644 index 0000000..da58860 --- /dev/null +++ b/works/SysProg/ПР 2/Задание 3.c @@ -0,0 +1,45 @@ +#include +#include + +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; +} \ No newline at end of file