-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_4.c
32 lines (23 loc) · 861 Bytes
/
test_4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
int main()
{
float fval = 12.34f;
int *iptr = (int *) &fval;
double db_num_p = 0.0;
double db_num_n = -0.0;
printf("positive : %8x, negative: %8x\n", db_num_p, db_num_n);
if (db_num_p == db_num_n) { printf("p == n\n"); }
else { printf("p!=n\n"); }
// type conversion
// let compiler can treat the pointer with another way.
// so move pointer will change the move step.
printf("%f -> 0x%08x\n", fval, fval);
printf("%f -> 0x%08x\n", fval, *iptr);
printf("%f -> 0x%08x\n", fval, fval);
fval = 1 / 0.0f;
printf("%f -> 0x%08x\n", fval, *iptr);
// output: inf -> 0x7f800000
fval = 0 / 0.0f;
printf("%f -> 0x%08x\n", fval, *iptr);
// output: -nan -> 0xffc00000
}