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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
| uses crt;
var m:array[1..32] of integer;
n:array[1..64] of integer;
a:array[1..15] of integer;
a1:array[1..96] of integer;
w,l,w1,d:real;
pl2:real;
i,h,g,y,k,b,j,r,p,s,f1,j1,u,s1,i2,f,o,t,y3,e,kic,Err,x,x1,z,v:integer;
pl1:int64;
c,znak:char;
pr,pr1,pr2:string;
begin
znak:=' ';
c:='0';
h:=0;
j:=0;
o:=1;
s:=-1;
b:=15;
x:=0;
x1:=0;
v:=64;
z:=0;
t:=0;
k:=32;
y:=0;
clrscr;
writeln('введите число:');
Readln(pr);if(pr[1]='-')then begin c:='1';x:=1;end; if(pr='0') then x1:=1;
Writeln('Введите точность');
Writeln('1)Одиночная точность');
Writeln('2)Двойная точность');
Writeln('3)Расширенная точность');
Readln(f);
if (f=1) then begin i2:=23;end;
if (f=2) then begin i2:=52;end;
if (f=3) then begin i2:=64;end;
kic:=length(pr)+1;
for i:=1 to length(pr) do
begin
if (pr[i]='.') then begin kic:=i;break;end;
end;
pr1:=copy(pr,1,kic-1);
pr2:=copy(pr,kic+1,length(pr)-kic+1);
val(pr1, pl1,Err);
pl1:=abs(pl1);
val(pr2, pl2,Err);
writeln('_______________________________________________________________________________');
writeln('знак:');
writeln('_______________________________________________________________________________');
writeln(c);
if c='1' then begin znak:='-';p:=1;end;
writeln('_______________________________________________________________________________');
writeln('_______________________________________________________________________________');
if pl1+pl2=0 then x1:=1;
while (pl1<>0) do {перевод целого числа в доичную систему счисления}
begin
if (pl1 mod 2)=0 then m[k]:=0 else m[k]:=1;
pl1:=pl1
div 2;
k:=k-1;
end;
if pl2=1 then h:=1;
while (pl2>1) do {перевод дробной чсасти}
begin
pl2:=pl2/10
end;
while (v<>1) do
begin
pl2:=pl2*2;
if pl2>=1 then begin n[v]:=1;pl2:=pl2-1;end else n[v]:=0;
v:=v-1;
end;
for k:=1 to 32 do
if m[k]=1 then begin j:=1;u:=k;z:=k;break; end;
if j<>1 then begin begin
for v:=64 downto 1 do
if n[v]=1 then begin j:=2;g:=v;x:=v-1;t:=v;break;end;end;end;
r:=32-u;
writeln('Мантиса:');
writeln('_______________________________________________________________________________');
if (x1=1) and (f=1) then write('00000000000000000000000');
if (x1=1) and (f=2) then write('0000000000000000000000000000000000000000000000000000');
if (x1=1) and (f=3) then write('00000000000000000000000000000000000000000000000000000000000000');
if x1=1 then y3:=1;
if (j=1) and (u<9) and (f=1) then begin
begin
j1:=1;
for k:=u+1 to 23+u do
write(m[k])end;end else
if j=1 then begin
begin
j1:=2;
for k:=u+1 to 32 do
write(m[k]);end;
r:=(64-(i2-r)+1);
begin
for v:=64 downto r do
write(n[v]);end;end;
If j<>1 then begin
j1:=3;
g:=65-g;
g:=(64-(i2-g));if f=2 then g:=g-1;
begin
for v:=x downto g do
write(n[v]);end;end;
writeln;
writeln('_______________________________________________________________________________');
writeln('_______________________________________________________________________________');
writeln('Порядок:');
writeln('_______________________________________________________________________________');
t:=65-t;
if j=1 then z:=32-z else t:=t*(-1);
f1:=f;
if (j=1) and (f=1) then y:=z+127;
if (j=1) and (f=2) then y:=z+1023;
if (j=1) and (f=3) then y:=z+16383;
if (j=2) and (f=1) then y:=t+127;
if (j=2) and (f=2) then y:=t+1023;
if (j=2) and (f=3) then y:=t+16383;
while (y<>0) do {перевод порядка в доичную систему счисления}
begin
if (y mod 2)=0 then a[b]:=0 else a[b]:=1;
y:=y div 2;
b:=b-1;
end;
if f=1 then begin
for b:=8 to 15 do
write(a[b]); end;
if f=2 then begin
for b:=5 to 15 do
write(a[b]); end;
if f=3 then begin
for b:=1 to 15 do
write(a[b]); end;
writeln;
writeln('_______________________________________________________________________________');
for b:=15 downto 1 do
begin
e:=e+(a[b]*o);o:=o*2;
end;
if f1=3 then l:=exp(ln(2)*(e-16383));
if f1=2 then l:=exp(ln(2)*(e-1023));
if f1=1 then l:=exp(ln(2)*(e-127));
if j1=1 then begin
for k:=u+1 to 23+u do
begin
w:=w+(exp(ln(2)*s))*m[k];
s:=s-1;
end;end;
if j1=2 then begin
for k:=u+1 to 32 do
begin
w:=w+(exp(ln(2)*s))*m[k];
s:=s-1;
end;end;
s1:=s;
if j1=2 then begin
for v:=64 downto r do
begin
w1:=w1+(exp(ln(2)*s1))*n[v];
s1:=s1-1;
end;end;
w:=w1+w;
if j1=3 then begin
for v:=x downto g do
begin
w:=w+(exp(ln(2)*s))*n[v];
s:=s-1;
end;end;
if (y3<>1) and (h<>1) then begin
d:=(1+w)*l;
writeln;
writeln('Число:',znak,d);end;
if y3=1 then write('Число:','0');
if (h=1) and (j1=3) and (p=1) then write ('Число:','-0.1');
if (h=1) and (j1=3) and (p<>1) then write ('Число:','0.1');
if (h=1) and (j1=2) and (p<>1) then begin w:=w-w1;
d:=(1+w)*l;write('Число:',znak,d+0.1);end;
if (h=1) and (j1=2) and (p=1) then begin w:=w-w1;
d:=(1+w)*l;write('Число:',znak,d+0.1);end;
readln;
end. |