function y=test_truncnorm1(mu,var,a,b)
%TRUNCNORM1   Sample efficiently from the truncated  normal using the
%             function truncnorm.

t4=0.45;

s=sqrt(var);
c=(a-mu)/s;
b=(b-mu)/s;

if c==-inf
    c=-b;
    b=inf;

    if c<=t4
         z=-normalrej(c,b);
    else
         z=-exprej(c,b);
    end

else
    if c<=t4
         z=normalrej(c,b);
    else
         z=exprej(c,b);
    end
end

y=s*z+mu;