mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 17:49:25 +02:00
* RTL, fpc_val_real_shortstr(): somewhat simplified, functionality is not changed.
git-svn-id: trunk@25481 -
This commit is contained in:
parent
08543ddeba
commit
38c2fb755a
@ -1535,15 +1535,15 @@ var
|
|||||||
sign : valreal;
|
sign : valreal;
|
||||||
esign,
|
esign,
|
||||||
exponent,
|
exponent,
|
||||||
|
expstart,
|
||||||
decpoint : SizeInt;
|
decpoint : SizeInt;
|
||||||
flags : byte;
|
|
||||||
begin
|
begin
|
||||||
fpc_Val_Real_ShortStr:=0.0;
|
fpc_Val_Real_ShortStr:=0.0;
|
||||||
code:=1;
|
code:=1;
|
||||||
exponent:=0;
|
exponent:=0;
|
||||||
decpoint:=0;
|
decpoint:=0;
|
||||||
esign:=1;
|
esign:=1;
|
||||||
flags:=0;
|
hd:=0.0;
|
||||||
sign:=1;
|
sign:=1;
|
||||||
while (code<=length(s)) and (s[code] in [' ',#9]) do
|
while (code<=length(s)) and (s[code] in [' ',#9]) do
|
||||||
inc(code);
|
inc(code);
|
||||||
@ -1555,32 +1555,29 @@ begin
|
|||||||
inc(code);
|
inc(code);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
while (Code<=Length(s)) and (s[code] in ['0'..'9']) do
|
expstart:=code;
|
||||||
|
while (Code<=Length(s)) do
|
||||||
begin
|
begin
|
||||||
{ Read integer part }
|
case s[code] of
|
||||||
flags:=flags or 1;
|
'0'..'9':
|
||||||
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
|
hd:=hd*10+(ord(s[code])-ord('0'));
|
||||||
|
'.':
|
||||||
|
if decpoint=0 then
|
||||||
|
decpoint:=code
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
end;
|
||||||
inc(code);
|
inc(code);
|
||||||
end;
|
end;
|
||||||
{ Decimal ? }
|
{ must have seen at least one digit }
|
||||||
if (length(s)>=code) and (s[code]='.') then
|
if (code-expstart)<1+ord(decpoint<>0) then
|
||||||
begin
|
exit;
|
||||||
inc(code);
|
|
||||||
while (length(s)>=code) and (s[code] in ['0'..'9']) do
|
if decpoint<>0 then
|
||||||
begin
|
decpoint:=code-decpoint-1;
|
||||||
{ Read fractional part. }
|
|
||||||
flags:=flags or 2;
|
|
||||||
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*10+(ord(s[code])-ord('0'));
|
|
||||||
inc(decpoint);
|
|
||||||
inc(code);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
{ Again, read integer and fractional part}
|
|
||||||
if flags=0 then
|
|
||||||
begin
|
|
||||||
fpc_Val_Real_ShortStr:=0.0;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
{ Exponent ? }
|
{ Exponent ? }
|
||||||
if (length(s)>=code) and (s[code] in ['e','E']) then
|
if (length(s)>=code) and (s[code] in ['e','E']) then
|
||||||
begin
|
begin
|
||||||
@ -1594,18 +1591,19 @@ begin
|
|||||||
esign:=-1;
|
esign:=-1;
|
||||||
inc(code);
|
inc(code);
|
||||||
end;
|
end;
|
||||||
if (length(s)<code) or not(s[code] in ['0'..'9']) then
|
expstart:=code;
|
||||||
begin
|
|
||||||
fpc_Val_Real_ShortStr:=0.0;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
while (length(s)>=code) and (s[code] in ['0'..'9']) do
|
while (length(s)>=code) and (s[code] in ['0'..'9']) do
|
||||||
begin
|
begin
|
||||||
exponent:=exponent*10;
|
exponent:=exponent*10+(ord(s[code])-ord('0'));
|
||||||
exponent:=exponent+ord(s[code])-ord('0');
|
|
||||||
inc(code);
|
inc(code);
|
||||||
end;
|
end;
|
||||||
|
if code=expstart then
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
|
{ Not all characters are read ? }
|
||||||
|
if length(s)>=code then
|
||||||
|
exit;
|
||||||
|
|
||||||
{ adjust exponent based on decimal point }
|
{ adjust exponent based on decimal point }
|
||||||
if esign>0 then
|
if esign>0 then
|
||||||
begin
|
begin
|
||||||
@ -1620,7 +1618,7 @@ begin
|
|||||||
inc(exponent,decpoint);
|
inc(exponent,decpoint);
|
||||||
{ evaluate sign }
|
{ evaluate sign }
|
||||||
{ (before exponent, because the exponent may turn it into a denormal) }
|
{ (before exponent, because the exponent may turn it into a denormal) }
|
||||||
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr*sign;
|
fpc_Val_Real_ShortStr:=hd*sign;
|
||||||
|
|
||||||
{ Calculate Exponent }
|
{ Calculate Exponent }
|
||||||
hd:=1.0;
|
hd:=1.0;
|
||||||
@ -1645,13 +1643,6 @@ begin
|
|||||||
else
|
else
|
||||||
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr/hd;
|
fpc_Val_Real_ShortStr:=fpc_Val_Real_ShortStr/hd;
|
||||||
|
|
||||||
|
|
||||||
{ Not all characters are read ? }
|
|
||||||
if length(s)>=code then
|
|
||||||
begin
|
|
||||||
fpc_Val_Real_ShortStr:=0.0;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
{ success ! }
|
{ success ! }
|
||||||
code:=0;
|
code:=0;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user