# Strange behaviour of “Make Table” with exponential function

I am trying to create a simple interpolation of 1-Exp[-x^2] function, over the logarithmic grid, but I am stuck due to some unexpected behaviour:

(*grid creation:*)
grid = Table[10.0^-10*Exp[5*i], {i, 0, 10}];
(*function:*)
am[x_]:=1-Exp[-x^2]
(*grid: function vs. variable*)
Table[{grid[[i]], am[grid[[i]]]}, {i, 1, 10}]

{{1.*10^-10, 0.}, {1.48413*10^-8, 2.22045*10^-16}, {2.20265*10^-6, 4.85167*10^-12},
{0.000326902, 1.06865*10^-7}, {0.0485165, 0.00235108}, {7.20049, 1.},
{1068.65, 0.9999999999999999999999999999999999999999999999999......}}


and here Table is stuck. The problem occurs at large values of the variable grid[[7]].

It seems like 1-Exp[-x^2] cannot provide a stable result at large values of the argument.

Of course I can define a conditional expression like If[x>...,1,1-Exp[-x^2]] but I am eager to know how to treat this problem properly, since I work a lot with such unstable functions and need to to know how to prevent it in the future.

-

Note the change in first operation, from 10.0 to 10. This allows full arbitrary precision. Surrounding the final result in N gets you a numeric result with specified precision.

grid = Table[10^-10*Exp[5*i], {i, 0, 10}];

am[x_] := 1 - Exp[-x^2];

N[Table[{grid[[i]], am[grid[[i]]]}, {i, 1, 10}], 6]

(*
{{1.00000*10^-10,1.00000*10^-20},{1.48413*10^-8,2.20265*10^-16},
{2.20265*10^-6,4.85165*10^-12},{0.000326902,1.06865*10^-7},{0.0485165,0.00235108},
{7.20049,1.00000},{1068.65,1.00000},{158601.,1.00000},{2.35385*10^7,1.00000},
{3.49343*10^9,1.00000}}
*)

-
you are right, but if I need a Real number instead of 10^(-10), for example 6.35^{-15}, then your suggestion will not work. There is something intrinsic in this approach which I do not get. –  A.K. May 12 '14 at 9:31
@A.K.: Take a look at precision/accuracy related questions here, and in the documentation. Bottom line is if a number is specified with low precision (e.g. by giving only a small number of decimals), and not otherwise marked or massaged to higher precision (e.g. using 635/10*10^(-15) in your comment example), you'll get underflow with the kinds of calculations your doing. –  ciao May 12 '14 at 9:40
A number can be converted to an exact number using Rationalize. x1 = Rationalize[6.35^(-15), 0]  returns 37/40719984446690 –  Bob Hanlon Jun 11 '14 at 19:02