алогритм вывода числа с погрешностью
Добавить всякие En - проще простого - умножением на 10...
const
trunclen=3;
function Fuck(x,s:real):string;
begin
Fuck:=floattoint(x,trunclen)+'+/-'+floattoint(s,trunclen);
end;
Не так всё просто.
Дык, даже приведенные тесты-то эта функция не проходит.
надо?
давай
function WriteRes(y, s:float) : string;
var
ex1, ex2, ex3, ex4 : integer;
st,st1 :string;
zn : boolean;
begin
if y <0 then
begin
y := -y;
zn := True;
end
else
zn :=False;
st := '';ex2 := 0;
if s<>0 then
Ex4 := Up(ln(s)/ln(10
else
ex4 := 0;
if y <>0 then
Ex1 := Up(ln(y)/ln(10
else
ex1 := 0;
if y =1 then
Ex1 := 1;
if (ex1-ex2>2)or(ex1-ex2<-1) then
begin
ex2 := ex2 + ex4;
end;
if ex1-ex2) in [0..2])and(ex4-ex2<-1) then ex2 := 0;
if (ex1-ex4 < 1)and(y<>0) then ex2 := ex4-1;
if ex1-ex2>4 then ex2 := ex2 + (ex1-ex2-3);
if abs(ex2) = 1 then
if (ex2>0)or(ex1-ex2>3) then
inc(ex2)
else
if ex4-ex2<0 then
ex2:=0
else
dec(ex2);
ex3 := ex2-ex4;
if ex3<0 then
ex3 := 0;
if (ex2<>0) then
st:= st+'(';
s:=s/pow(10,ex2);
y:=y/pow(10,ex2);
Str(y:1:ex3,St1);
st:=st+st1;
if s<>0 then
begin
Str(s:1:ex3,St1);
st:=st+' + '+st1;
end;
if (ex2<>0) then st:= st+') * 10^'+inttostr(ex2);
if zn then st := '- '+st;
Result := st;
end;
function up(x:float):integer;
begin
if x=trunc(x) then up := trunc(x)
else
if x>0 then up := trunc(x)
else
up := trunc(x) - 1;
end;
Оставить комментарий
garikus
x ± sВ инете найти не могу. Может кто предложит готовый ?
PROCEDURE Real (x, s: REAL; OUT str: ARRAY OF CHAR);
Примеры: