procedure sprod(var x1,x2,x3: scalar);
var
  t: boolean;
  r: hreal;
begin { sprod }
  underflow:=false;
  if ((x1.u.si=0) and (x1.l.si=0)) or ((x2.u.si=0) and (x2.l.si=0)) then begin
    x3.u.si:=0;
    x3.l.si:=0;
  end
  else if x1.l.si>=0 then begin
    if x2.l.si>=0 then begin
      rprod(x1.l,x2.l,x3.l);
      r_prod(up,x1.u,x2.u,x3.u);
    end
    else if x2.u.si<=0 then begin
      r_prod(down,x1.u,x2.l,x3.l);
      rprod(x1.l,x2.u,x3.u);
    end
    else begin
      r_prod(down,x1.u,x2.l,x3.l);
      r_prod(up,x1.u,x2.u,x3.u);
    end;
  end
  else if x1.u.si<=0 then begin
    if x2.l.si>=0 then begin
      r_prod(down,x1.l,x2.u,x3.l);
      rprod(x1.u,x2.l,x3.u);
    end
    else if x2.u.si<=0 then begin
      rprod(x1.u,x2.u,x3.l);
      r_prod(up,x1.l,x2.l,x3.u);
    end
    else begin
      r_prod(down,x1.l,x2.u,x3.l);
      r_prod(up,x1.l,x2.l,x3.u);
    end;
  end
  else begin
    if x2.l.si>=0 then begin
      r_prod(down,x1.l,x2.u,x3.l);
      r_prod(up,x1.u,x2.u,x3.u);
    end
    else if x2.u.si<=0 then begin
      r_prod(down,x1.u,x2.l,x3.l);
      r_prod(up,x1.l,x2.l,x3.u);
    end
    else begin
      rprod(x1.l,x2.u,r);
      t:=trunc;
      rprod(x1.u,x2.l,x3.l);
      if irdiff(r,x3.l)<0 then begin
        if t then rdown(r);
        x3.l:=r;
      end
      else if trunc then rdown(x3.l);
      rprod(x1.l,x2.l,r);
      t:=trunc;
      rprod(x1.u,x2.u,x3.u);
      if irdiff(r,x3.u)>0 then begin
        if t then rup(r);
        x3.u:=r;
      end
      else if trunc then rup(x3.u);
    end;
  end;
  if underflow then snormalize(x3);
end { sprod };

