mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 17:49:13 +02:00
* small speed improvements
This commit is contained in:
parent
f3079dff58
commit
a4b08bdef9
@ -47,7 +47,7 @@ var correct : longint; { Power correction }
|
|||||||
sign : boolean;
|
sign : boolean;
|
||||||
i : integer;
|
i : integer;
|
||||||
dot : byte;
|
dot : byte;
|
||||||
|
currp : pchar;
|
||||||
begin
|
begin
|
||||||
case real_type of
|
case real_type of
|
||||||
rt_s32real :
|
rt_s32real :
|
||||||
@ -90,7 +90,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
{ check parameters }
|
{ check parameters }
|
||||||
{ default value for length is -32767 }
|
{ default value for length is -32767 }
|
||||||
if len=-32767 then len:=maxlen;
|
if len=-32767 then
|
||||||
|
len:=maxlen;
|
||||||
{ determine sign. before precision, needs 2 less calls to abs() }
|
{ determine sign. before precision, needs 2 less calls to abs() }
|
||||||
sign:=d<0;
|
sign:=d<0;
|
||||||
{ the creates a cannot determine which overloaded function to call
|
{ the creates a cannot determine which overloaded function to call
|
||||||
@ -100,32 +101,35 @@ begin
|
|||||||
|
|
||||||
{ d:=abs(d); this converts d to double so we loose precision }
|
{ d:=abs(d); this converts d to double so we loose precision }
|
||||||
{ for the same reason I converted d:=frac(d) to d:=d-int(d); (PM) }
|
{ for the same reason I converted d:=frac(d) to d:=d-int(d); (PM) }
|
||||||
if sign then d:=-d;
|
if sign then
|
||||||
|
d:=-d;
|
||||||
{ determine precision : maximal precision is : }
|
{ determine precision : maximal precision is : }
|
||||||
currprec:=maxlen-explen-3;
|
currprec:=maxlen-explen-3;
|
||||||
{ this is also the maximal number of decimals !!}
|
{ this is also the maximal number of decimals !!}
|
||||||
if f>currprec then f:=currprec;
|
if f>currprec then
|
||||||
|
f:=currprec;
|
||||||
{ when doing a fixed-point, we need less characters.}
|
{ when doing a fixed-point, we need less characters.}
|
||||||
if (f<0) or ( (d<>0) and ((d>maxexp) or (d<minexp))) then
|
if (f<0) or ( (d<>0) and ((d>maxexp) or (d<minexp))) then
|
||||||
begin
|
begin
|
||||||
{ determine maximal number of decimals }
|
{ determine maximal number of decimals }
|
||||||
if (len>=0) and (len<minlen) then len:=minlen;
|
if (len>=0) and (len<minlen) then
|
||||||
if (len>0) and (len<maxlen) then
|
len:=minlen;
|
||||||
currprec:=len-explen-3;
|
if (len>0) and (len<maxlen) then
|
||||||
|
currprec:=len-explen-3;
|
||||||
end;
|
end;
|
||||||
{ convert to standard form. }
|
{ convert to standard form. }
|
||||||
correct:=0;
|
correct:=0;
|
||||||
if d>=i10 then
|
if d>=i10 then
|
||||||
while d>=i10 do
|
while d>=i10 do
|
||||||
begin
|
begin
|
||||||
d:=d/i10;
|
d:=d/i10;
|
||||||
inc(correct);
|
inc(correct);
|
||||||
end
|
end
|
||||||
else if (d<1) and (d<>0) then
|
else if (d<1) and (d<>0) then
|
||||||
while d<1 do
|
while d<1 do
|
||||||
begin
|
begin
|
||||||
d:=d*i10;
|
d:=d*i10;
|
||||||
dec(correct);
|
dec(correct);
|
||||||
end;
|
end;
|
||||||
{ RoundOff }
|
{ RoundOff }
|
||||||
roundcorr:=extended(i1)/extended(i2);
|
roundcorr:=extended(i1)/extended(i2);
|
||||||
@ -154,53 +158,61 @@ begin
|
|||||||
{ Now we have a standard expression : sign d *10^correct
|
{ Now we have a standard expression : sign d *10^correct
|
||||||
where 1<d<10 or d=0 ... }
|
where 1<d<10 or d=0 ... }
|
||||||
{ get first character }
|
{ get first character }
|
||||||
|
currp:=pchar(@temp[1]);
|
||||||
if sign then
|
if sign then
|
||||||
temp:='-'
|
currp^:='-'
|
||||||
else
|
else
|
||||||
temp:=' ';
|
currp^:=' ';
|
||||||
temp:=temp+chr(ord('0')+trunc(d));
|
inc(currp);
|
||||||
|
currp^:=chr(ord('0')+trunc(d));
|
||||||
|
inc(currp);
|
||||||
d:=d-int(d);
|
d:=d-int(d);
|
||||||
{ Start making the string }
|
{ Start making the string }
|
||||||
for i:=1 to currprec do
|
for i:=1 to currprec do
|
||||||
begin
|
begin
|
||||||
d:=d*i10;
|
d:=d*i10;
|
||||||
temp:=temp+chr(ord('0')+trunc(d));
|
currp^:=chr(ord('0')+trunc(d));
|
||||||
d:=d-int(d);
|
inc(currp);
|
||||||
end;
|
d:=d-int(d);
|
||||||
|
end;
|
||||||
|
temp[0]:=chr(currp-pchar(@temp[1]));
|
||||||
{ Now we need two different schemes for the different
|
{ Now we need two different schemes for the different
|
||||||
representations. }
|
representations. }
|
||||||
if (f<0) or (correct>maxexp) then
|
if (f<0) or (correct>maxexp) then
|
||||||
begin
|
begin
|
||||||
insert ('.',temp,3);
|
insert ('.',temp,3);
|
||||||
str(abs(correct),power);
|
str(abs(correct),power);
|
||||||
if length(power)<explen-2 then
|
if length(power)<explen-2 then
|
||||||
power:=copy(zero,1,explen-2-length(power))+power;
|
power:=copy(zero,1,explen-2-length(power))+power;
|
||||||
if correct<0 then power:='-'+power else power:='+'+power;
|
if correct<0 then
|
||||||
temp:=temp+'E'+power;
|
power:='-'+power
|
||||||
|
else
|
||||||
|
power:='+'+power;
|
||||||
|
temp:=temp+'E'+power;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if not sign then
|
if not sign then
|
||||||
begin
|
|
||||||
delete (temp,1,1);
|
|
||||||
dot:=2;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
dot:=3;
|
|
||||||
{ set zeroes and dot }
|
|
||||||
if correct>=0 then
|
|
||||||
begin
|
begin
|
||||||
if length(temp)<correct+dot+f then
|
delete (temp,1,1);
|
||||||
temp:=temp+copy(zero,1,correct+dot+f-length(temp));
|
dot:=2;
|
||||||
insert ('.',temp,correct+dot);
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
dot:=3;
|
||||||
correct:=abs(correct);
|
{ set zeroes and dot }
|
||||||
insert(copy(zero,1,correct),temp,dot-1);
|
if correct>=0 then
|
||||||
insert ('.',temp,dot);
|
begin
|
||||||
|
if length(temp)<correct+dot+f then
|
||||||
|
temp:=temp+copy(zero,1,correct+dot+f-length(temp));
|
||||||
|
insert ('.',temp,correct+dot);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
correct:=abs(correct);
|
||||||
|
insert(copy(zero,1,correct),temp,dot-1);
|
||||||
|
insert ('.',temp,dot);
|
||||||
end;
|
end;
|
||||||
{correct length to fit precision.}
|
{ correct length to fit precision }
|
||||||
if f>0 then
|
if f>0 then
|
||||||
temp[0]:=chr(pos('.',temp)+f)
|
temp[0]:=chr(pos('.',temp)+f)
|
||||||
else
|
else
|
||||||
@ -214,7 +226,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.13 1999-05-06 09:05:12 peter
|
Revision 1.14 1999-08-03 21:58:44 peter
|
||||||
|
* small speed improvements
|
||||||
|
|
||||||
|
Revision 1.13 1999/05/06 09:05:12 peter
|
||||||
* generic write_float str_float
|
* generic write_float str_float
|
||||||
|
|
||||||
Revision 1.12 1999/03/10 21:49:02 florian
|
Revision 1.12 1999/03/10 21:49:02 florian
|
||||||
|
@ -593,7 +593,11 @@ Function NextChar(var f:TextRec;var s:string):Boolean;
|
|||||||
begin
|
begin
|
||||||
if f.BufPos<f.BufEnd then
|
if f.BufPos<f.BufEnd then
|
||||||
begin
|
begin
|
||||||
s:=s+f.BufPtr^[f.BufPos];
|
if length(s)<high(s) then
|
||||||
|
begin
|
||||||
|
inc(s[0]);
|
||||||
|
s[length(s)]:=f.BufPtr^[f.BufPos];
|
||||||
|
end;
|
||||||
Inc(f.BufPos);
|
Inc(f.BufPos);
|
||||||
If f.BufPos>=f.BufEnd Then
|
If f.BufPos>=f.BufEnd Then
|
||||||
FileFunc(f.InOutFunc)(f);
|
FileFunc(f.InOutFunc)(f);
|
||||||
@ -776,11 +780,11 @@ var
|
|||||||
Begin
|
Begin
|
||||||
{ Delete the string }
|
{ Delete the string }
|
||||||
Setlength(S,0);
|
Setlength(S,0);
|
||||||
Repeat
|
Repeat
|
||||||
// SetLength will reallocate the length.
|
// SetLength will reallocate the length.
|
||||||
SetLength(S,Length(S)+255);
|
SetLength(S,Length(S)+255);
|
||||||
len:=ReadPCharLen(f,pchar(Pointer(S)+Length(S)-255),255);
|
len:=ReadPCharLen(f,pchar(Pointer(S)+Length(S)-255),255);
|
||||||
If Len<255 then
|
If Len<255 then
|
||||||
// Set actual length
|
// Set actual length
|
||||||
SetLength(S,Length(S)-255+Len);
|
SetLength(S,Length(S)-255+Len);
|
||||||
Until len<255;
|
Until len<255;
|
||||||
@ -941,7 +945,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.51 1999-07-26 09:43:24 florian
|
Revision 1.52 1999-08-03 21:58:45 peter
|
||||||
|
* small speed improvements
|
||||||
|
|
||||||
|
Revision 1.51 1999/07/26 09:43:24 florian
|
||||||
+ write helper routine for in64 implemented
|
+ write helper routine for in64 implemented
|
||||||
|
|
||||||
Revision 1.50 1999/07/08 15:18:14 michael
|
Revision 1.50 1999/07/08 15:18:14 michael
|
||||||
|
Loading…
Reference in New Issue
Block a user