PZ
This commit is contained in:
@@ -1,3 +1,49 @@
|
|||||||
|
Çàäàíèå 1:
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
union FloatPacker {
|
||||||
|
float f;
|
||||||
|
struct {
|
||||||
|
uint32_t mantissa : 23;
|
||||||
|
uint32_t exponent : 8;
|
||||||
|
uint32_t sign : 1;
|
||||||
|
} parts;
|
||||||
|
};
|
||||||
|
|
||||||
|
float make_float(uint32_t sign, uint32_t exp, uint32_t mantissa) {
|
||||||
|
union FloatPacker packer;
|
||||||
|
|
||||||
|
packer.parts.sign = sign & 0x1;
|
||||||
|
packer.parts.exponent = exp & 0xFF;
|
||||||
|
packer.parts.mantissa = mantissa & 0x7FFFFF;
|
||||||
|
|
||||||
|
return packer.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
float one = make_float(0, 127, 0);
|
||||||
|
printf("Ñáîðêà 1.0f: %f\n", one);
|
||||||
|
float minus_two_point_five = make_float(1, 128, 0x200000);
|
||||||
|
printf("Ñáîðêà -2.5f: %f\n", minus_two_point_five);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Çàäàíèå 2:
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int is_nan(float f) {
|
||||||
|
uint32_t raw;
|
||||||
|
memcpy(&raw, &f, sizeof(raw));
|
||||||
|
uint32_t exp = (raw >> 23) & 0xFF;
|
||||||
|
uint32_t mantissa = raw & 0x7FFFFF;
|
||||||
|
return (exp == 0xFF) && (mantissa != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Çàäàíèå 3:
|
Çàäàíèå 3:
|
||||||
|
|
||||||
float Q_rsqrt( float number )
|
float Q_rsqrt( float number )
|
||||||
|
|||||||
Reference in New Issue
Block a user