#define _CRT_SECURE_NO_WARNINGS
#include <float.h>
#include <math.h>
#include <stdio.h>
#define max(a,b) (((a)>(b))?(a):(b))
void dispf(float f)
{
char str[32];
char* pc;
unsigned char* pf;
int i, b;
pf = (unsigned char*)&f;
pc = str;
for (i = 0; i < 4; i++) {
for (b = 0; b < 8; b++) {
*pc++ = '0'+((pf[3-i]>>(7-b))&1);
}
}
printf("%.1s %.8s %.23s\n", str
, str
+ 1, str
+ 9); }
int main()
{
float a, b, c, d;
a = (float)1970.2;
dispf(a);
a = (float)1970.199707;
dispf(a);
sscanf("1.970200E+03", "%E", &b
); dispf(b);
c = fabsf(a - b);
dispf(c);
d = FLT_EPSILON;
dispf(d);
printf("d = max(fabsf(a), fabsf(b))\n"); d = max(fabsf(a), fabsf(b));
dispf(d);
printf("d = FLT_EPSILON * max(fabsf(a), fabsf(b))\n"); d = FLT_EPSILON * max(fabsf(a), fabsf(b));
dispf(d);
printf("%s\n", (c
<=d
)?"true":"false"); return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8ZmxvYXQuaD4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIG1heChhLGIpICgoKGEpPihiKSk/KGEpOihiKSkKCnZvaWQgZGlzcGYoZmxvYXQgZikKewoJY2hhcgkJc3RyWzMyXTsKCWNoYXIqCQlwYzsKCXVuc2lnbmVkIGNoYXIqCXBmOwoJaW50CQlpLCBiOwoKCXBmID0gKHVuc2lnbmVkIGNoYXIqKSZmOwoJcGMgPSBzdHI7Cglmb3IgKGkgPSAwOyBpIDwgNDsgaSsrKSB7CgkJZm9yIChiID0gMDsgYiA8IDg7IGIrKykgewoJCQkqcGMrKyA9ICcwJysoKHBmWzMtaV0+Pig3LWIpKSYxKTsKCQl9Cgl9CglwcmludGYoIiUuMXMgJS44cyAlLjIzc1xuIiwgc3RyLCBzdHIgKyAxLCBzdHIgKyA5KTsKC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