From 8ac3f0d7d1a2875abdeea14b3dfd5804e2a88378 Mon Sep 17 00:00:00 2001 From: anastasosmoho Date: Thu, 1 Oct 2026 18:15:06 +0000 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- works/pr2/1realizacia/main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 works/pr2/1realizacia/main.c diff --git a/works/pr2/1realizacia/main.c b/works/pr2/1realizacia/main.c new file mode 100644 index 0000000..93d80fd --- /dev/null +++ b/works/pr2/1realizacia/main.c @@ -0,0 +1,28 @@ +#include +#include +// Структура для хранения отдельных полей +union FloatBits { + float f; + uint32_t bits; + +}; +float build_float(uint32_t sign, uint32_t exp, uint32_t mantissa) { + union FloatBits u; + u.bits = ((sign & 1u) << 31) + | ((exp & 0xFFu) << 23) + | (mantissa & 0x7FFFFFu); + return u.f; + +} +int main() { + float one = build_float(0, 127, 0); // 1.0 + float neg_two_five = build_float(1, 128, 0x200000); // -2.5 + float half = build_float(0, 126, 0); //0.5 + printf("1.0 = %f\n", one); + printf("-2.5 = %f\n", neg_two_five); + printf("0.5 = %f\n", half); + return 0; +} + + + \ No newline at end of file