function u = hreflect(x)
%HREFLECT Generate Householder reflection.
% u = hreflect(x) returns u with norm(u) = 1, and
% H(u,x) = x - 2*u*(u'*x) = -+ norm(x)*e_1.
    
    % Modify the sign function so that sign(0) = 1.
    sig = @(u) sign(u) + (u==0);
    
    nu = norm(x);
    u = x/nu;
    u(1) = u(1) + sig(u(1));
    u = u/(sqrt(2*abs(u(1))));
end
