?????????C ????? x == x???????????
?????GFree_Wind ???????[ 2016/11/22 11:37:56 ] ??????????????????? C
????????????????C????? x == x?????????????????????
????if (x == x) {
????printf("Equaln");
????}
????else {
????printf("Not equaln");
????}
?????????????”Not equal”??????????????ɡ?x??????????????????????????????????????????
??????????????????????????????????????????ж?x == x????false??????????????????????
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
float x = 0xffffffff;
if (x == x) {
printf("Equal
");
}
else {
printf("Not equal
");
}
if (x >= 0) {
printf("x(%f) >= 0
"?? x);
}
else if (x < 0) {
printf("x(%f) < 0
"?? x);
}
int a = 0xffffffff;
memcpy(&x?? &a?? sizeof(x));
if (x == x) {
printf("Equal
");
}
else {
printf("Not equal
");
}
if (x >= 0) {
printf("x(%f) >= 0
"?? x);
}
else if (x < 0) {
printf("x(%f) < 0
"?? x);
}
else {
printf("Surprise x(%f)!!!
"?? x);
}
return 0;
}
????????gcc -g -Wall test.c??????н????
????[fgao@fgao-vm-fc13 test]$ ./a.out
????Equal
????x(4294967296.000000) >= 0
????Not equal
????Surprise x(-nan)!!!
?????????е??????????е?surprise????
?????????????????£?
????1. ??float x = 0xffffffff??????????????????????????????float??int??size????4????????????洢??????????????????????Щλ???С??λ??????float???Χ?С??int???Χ???????????浽??????????????漲——????????????????????????????????????????????????????????????????????????????????????????????????——?????????????ΧС?????????Χ???
????2. ????????????????????????????????????????????????????????????????x == x??????true????x???????0????С??0?????x????????0xffffffff??
????3. ?????memcpy??0xff???x??????????x??????0xffffffff???????????????????????????float?????????????????????x????????x???????????cpu?????????????????????????????????
????4. ???????????float??????????????κ????????????????false??????????????澪???????x??????????0?????С??0??
?????????£?????????????????????????????????????й?????á???????Ч????????????????????????????洢???????????????Щ???????????????????????????????С??С????С??????????????????????????????????κα???ж?????????ж???????????????????????x != x?????????????????????
??????????????У??е??????????????????????????????????????????????????????????????????????????е?0???????????0.0????????????????????????????
???????????????????????????????????memcpy????両???μ??????????????????????????????????????????????????2???????????exception????NaN?????????????????????????????memcpy???????????0xffffffff???????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11