-
Notifications
You must be signed in to change notification settings - Fork 0
/
zad.c
71 lines (56 loc) · 1.44 KB
/
zad.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
double doAdd();
void SaveControlWord(int x);
unsigned short int ReadControlWord();
double changeRCup();
double changeRCdown();
void print_binary(double d){
unsigned long long *double_int = (unsigned long long *)&d;
int i;
for(i=0;i<=63;i++)
{
if(i==1){
printf (" ");
}
if(i==12){
printf(" ");
}
if((*double_int >> (63-i)) & 1)
printf("1");
else
printf("0");
}
printf("\n");
}
void print_binary_controlWord(unsigned short int cw){
for(int i=15;i>=0;i--){
printf("%d",(cw>>i)&1);
}
}
int main(){
printf("Zaokraglenie round to even, domyślne\n");
unsigned short int controlword1 = ReadControlWord();
printf("Binarna reprezentacja rejestru sterującego: \n");
print_binary_controlWord(controlword1);
printf("\n");
double result=doAdd();
printf("%.17g\n",result);
print_binary(result);
printf("Zaokraglenie do plus nieskonczonosci\n");
double test = changeRCup();
unsigned short int controlword = ReadControlWord();
printf("Binarna reprezentacja rejestru sterującego: \n");
print_binary_controlWord(controlword);
printf("\n");
printf("%.17g\n",test);
print_binary(test);
printf ("Zaokrąglenie do minus nieskończoności\n");
double test2=changeRCdown();
unsigned short int controlword3 = ReadControlWord();
printf("Binarna reprezentacja rejestru sterującego: \n");
print_binary_controlWord(controlword3);
printf("\n");
printf("%.17g\n",test2);
print_binary(test2);
return 0;
}