generated from admin/template
28 lines
720 B
C
28 lines
720 B
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
void analyze_float(float f) {
|
|
uint32_t bits;
|
|
memcpy(&bits, &f, sizeof(float)); // безопасный type punning
|
|
|
|
uint32_t sign = (bits >> 31) & 1;
|
|
uint32_t exp = (bits >> 23) & 0xFF;
|
|
uint32_t mant = bits & 0x7FFFFF;
|
|
|
|
printf("Float: %f\n", f);
|
|
printf("Hex bits: 0x%08X\n", bits);
|
|
printf("Sign: %u, Exp: %u (реальный: %d), Mantissa: 0x%06X\n",
|
|
sign, exp, (int)exp - 127, mant);
|
|
}
|
|
|
|
int main() {
|
|
analyze_float(1.0f);
|
|
analyze_float(-1.0f);
|
|
analyze_float(0.1f);
|
|
analyze_float(3.14f);
|
|
analyze_float(1.0f / 0.0f); // +inf
|
|
analyze_float(0.0f / 0.0f); // NaN
|
|
|
|
return 0;
|
|
} |