-
Notifications
You must be signed in to change notification settings - Fork 30
/
2-special-numbers.c
32 lines (27 loc) · 1.06 KB
/
2-special-numbers.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>
#include <math.h>
float special_numbers[] = { 0.0, -0.0, INFINITY, -INFINITY, NAN, -NAN };
char *special_numbers_names[] = { "0.0", "-0.0", "INFINITY", "-INFINITY", "NAN", "-NAN" };
void display_float_in_binary(float f) {
char *d = (char *)&f;
for (int i = 0; i < sizeof(f); i++) {
printf("%.2x ", d[i] & 0xff);
}
printf("\n");
}
int main() {
for (int i = 0; i < 6; i++) {
printf("Number %s\tbin: ", special_numbers_names[i]);
display_float_in_binary(special_numbers[i]);
}
printf("\n");
for (int i = 0; i < 6; i++) {
for (int j = i; j < 6; j++) {
printf("%s == %s:\t%d\n", special_numbers_names[i], special_numbers_names[j], special_numbers[i] == special_numbers[j]);
printf("%s < %s:\t%d\n", special_numbers_names[i], special_numbers_names[j], special_numbers[i] < special_numbers[j]);
printf("%s > %s:\t%d\n", special_numbers_names[i], special_numbers_names[j], special_numbers[i] > special_numbers[j]);
printf("\n");
}
}
return 0;
}