procedure srset(s: longstring; var x: hreal);
var
  c: char;
  m,n,j,d: integer;
  p10,e10: integer32;

function isdigit(c: char; var d: integer): boolean;
{ d:=(digit described by c) }
begin { isdigit }
  d:=ord(c)-48;
  isdigit:=(d>=0) and (d<=9);
end { isdigit };

begin { srset }
  e10:=0;
  p10:=1;
  m:=length(s);
  repeat                                           { parse exponent }
    c:=s[m];
    if isdigit(c,d) then begin
      e10:=e10+d*p10;
      p10:=10*p10;
    end;
    m:=m-1;
  until (c='+') or (c='-');
  if c='+' then x.ex:=e10 div 4
  else begin
    x.ex:=-((e10+3) div 4);
    e10:=-e10;
  end;
  x.si:=1;
  for n:=0 to hdim do x.ma[n]:=0;
  trunc:=false;
  p10:=1000;
  for j:=2 downto (e10-4*x.ex) do p10:=p10 div 10;
  n:=0;
  for j:=1 to m-1 do begin                          { parse mantissa }
    c:=s[j];
    if c='-' then x.si:=-x.si
    else if isdigit(c,d) then begin
      if n<=hdim then begin
        x.ma[n]:=x.ma[n]+d*p10;
        p10:=p10 div 10;
        if p10=0 then begin
          n:=n+1;
          p10:=1000;
        end;
      end
      else trunc:=true;
    end;
  end;    
  rnormalize(x);
end { srset };

