Fix lab-2 folder and restore all works

This commit is contained in:
2026-09-29 10:01:08 +03:00
parent a540798739
commit abb6e74ad7
23 changed files with 562 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdint.h>
// объединение для сборки float из битовых полей
typedef union {
float f;
struct {
uint32_t mantissa : 23; // 23 бита мантиссы
uint32_t exp : 8; // 8 бит экспоненты
uint32_t sign : 1; // 1 бит знака
} parts;
} CustomFloat;
// для сборки float из отдельных компонентов
float make_float(uint8_t sign, uint8_t exp, uint32_t mantissa) {
CustomFloat cf;
cf.parts.sign = sign;
cf.parts.exp = exp;
cf.parts.mantissa = mantissa;
return cf.f;
}
int main() {
// 1 число 1.0f (Sign: 0, Exp: 127, Mantissa: 0)
float f1 = make_float(0, 127, 0);
printf("make_float(0, 127, 0) = %f\n", f1);
// 2 отрицательное число -1.0f (Sign: 1, Exp: 127, Mantissa: 0)
float f2 = make_float(1, 127, 0);
printf("make_float(1, 127, 0) = %f\n", f2);
// 3 число 1.5f (Sign: 0, Exp: 127, Mantissa: 0x400000 = 0.5 в двоичном виде)
float f3 = make_float(0, 127, 0x400000);
printf("make_float(0, 127, 0x400000) = %f\n", f3);
return 0;
}