function [expNew, m] = limExp(x)
% newExp(x) calculates exp(x) using limit (1+x/N+(x/N)^2/2)^N -> exp(x) as N -> Inf  

expOld = 1;   % variable storing the old, (m-1)-st value of result.
tol = 1e-6;   % error tolerance level 

for m=1:1000
    N = 2^m;
    expNew = (1 + x/N + (x/N)^2/2)^N;
    if ( abs(expOld - expNew) < tol ) return;
    elseif (isnan(expNew) || abs(expNew)==Inf)
        fprintf('Terminating: indeterminate term at m=%d\n', m);
        return;
    end;
    expOld = expNew;  % new value becomes old value at next loop iteration 
end;
    
fprintf('Warning: maximal iteration number has been reached\n');