N
Details
- Unless numbers in expr are exact, or of sufficiently high precision, N[expr,n] may not be able to give results with n‐digit precision.
- N[expr,n] may internally do computations to more than n digits of precision.
- $MaxExtraPrecision specifies the maximum number of extra digits of precision that will ever be used internally.
- The precision n is given in decimal digits; it need not be an integer.
- n must lie between $MinPrecision and $MaxPrecision. $MaxPrecision can be set to Infinity.
- n can be smaller than $MachinePrecision.
- N[expr] gives a machine‐precision number, so long as its magnitude is between $MinMachineNumber and $MaxMachineNumber.
- N[expr] is equivalent to N[expr,MachinePrecision].
- N[0] gives the number 0. with machine precision.
- N converts all nonzero numbers to Real or Complex form.
- N converts each successive argument of any function it encounters to numerical form, unless the head of the function has an attribute such as NHoldAll.
- You can define numerical values of functions using N[f[args]]:=value and N[f[args],n]:=value.
- N[expr,{p,a}] attempts to generate a result with precision at most p and accuracy at most a.
- N[expr,{Infinity,a}] attempts to generate a result with accuracy a.
- N[expr,{Infinity,1}] attempts to find a numerical approximation to the integer part of expr.
Examples
open all close allBasic Examples (3)
N[1 / 7]Evaluate numerically to 50-digit precision:
N[1 / 7, 50]With machine-precision input, the results are always machine precision:
N[Gamma[3.3], 50]With exact input, the results can be to the precision specified:
N[Gamma[33 / 10], 50]Scope (20)
Mathematical Constants (4)
Evaluate mathematical constants to any precision:
N[Pi, 50]N[Khinchin, 50]Get approximate values for large integers:
N[1000!]N[2 ^ 1000000]N[ArcSin[3]]More elaborate symbolic mathematical constants can be detected using NumericQ:
c = Exp[Sin[Sqrt[2]] + BesselJ[3, 4]];NumericQ[c]In general, NumericQ expressions represent numbers that can be evaluated to any precision:
N[c]N[c, 47]General Expressions (3)
Evaluate the entries of a matrix numerically:
m = {{Cos[1], Sin[1]}, {-Sin[1], Cos[1]}};N[m]Evaluate numerically the numeric parts of a symbolic expression:
N[(Pi + 2 x) / (E - x), 20]Make the coefficients of a polynomial numerical:
poly = Expand[Product[(x - i), {i, 10}]]N[poly]Machine and Adaptive Precision (4)
N[e] typically works by replacing numbers with machine numbers and computing the result:
e[h_] = Cos[1] - (Sin[1 + h] - Sin[1 - h]) / (2 h)N[e[10 ^ -12]]This is equivalent to the expression with machine numbers:
e[10. ^ -12]The machine roundoff error shows up clearly on a log-log plot of the difference quotient error:
ListLogLogPlot[h = 10 ^ -k;Table[{h, Abs[N[e[h]]]}, {k, 0, 16}]]N[e,p] works adaptively using arbitrary-precision numbers when p is not MachinePrecision:
e[h_] = Cos[1] - (Sin[1 + h] - Sin[1 - h]) / (2 h);N[e[10 ^ -12], 20]With adaptive precision, the difference quotient error matches the theoretical value:
Show[ListLogLogPlot[h = 10 ^ -k;Table[{h, Abs[N[e[h], 20]]}, {k, 0, 16}]],
LogLogPlot[Cos[1] h^2 / 6, {h, 10 ^ -16, 1}]]The adaptive precision control has a default limit, $MaxExtraPrecision, for extra precision:
N[1 - Sqrt[1 - Exp[-1000]], 20]When the limit is reached, you can locally increase $MaxExtraPrecision to resolve the difficulty:
Block[{$MaxExtraPrecision = 500}, N[1 - Sqrt[1 - Exp[-1000]], 20]]N does not raise the precision of approximate numbers in its input:
e = 1. + 2`20 x + 3`30x ^ 2N[e, 25]The precision of the result is the same as that of the input:
{Precision[%], Precision[e]}You can use SetPrecision to increase the precision of input expressions:
SetPrecision[e, 20]Data Objects and Special Rules (5)
N does not affect exact numeric powers:
N[x ^ (3 / 2)]N[Pi ^ x]The power is modified if it is not NumericQ:
N[E ^ (x + Pi)]NumericQ[x + Pi]SparseArray objects are treated based on the represented array:
s = SparseArray[{{i_, j_} /; Abs[i - j] ≤ 1 -> 3Abs[i - j] - 2}, {5, 5}]ns = N[s]{MatrixForm[s], MatrixForm[ns]}In general, N[Normal[s]] is identical to Normal[N[s]]:
N[Normal[s]] === Normal[N[s]]Data objects like InterpolatingFunction have special rules so that only the data is affected:
ifun = ListInterpolation[{0, 1, 1, 0}, {{0, 1}}]nifun = N[ifun]Only the appropriate data has been changed so that the new function uses machine numbers:
{ifun[1 / 2], nifun[1 / 2]}Operations like Integrate use the corresponding N-functions when appropriate:
int = Integrate[Sinc[Exp[-1 / x]], {x, 0, 1}]N[int]This is using NIntegrate:
NIntegrate[Sinc[Exp[-1 / x]], {x, 0, 1}]For high requested precision, numerical algorithms may take a lot of time or need adjustment:
Timing[N[int, 20]]In this case, you may want to use NIntegrate directly:
Timing[NIntegrate[Sinc[Exp[-1 / x]], {x, 0, 1}, WorkingPrecision -> 20]]For most expressions, N affects the tree shown in FullForm:
e = 2 - x;N[e]The 1. appears in front of x because of how e is represented:
FullForm[e]The integers in e have just been converted to machine numbers:
FullForm[N[e]]Defining Special Rules (4)
Prevent an indexed variable from being affected by N using the NHoldAll attribute:
SetAttributes[x, NHoldAll]With this, N only affects the coefficients:
N[1 + 2 x[1] + 3 x[2] + 4 x[1] x[2]]Without this, N affects the indices too:
N[1 + 2y[1] + 3 y[2] + 4 y[1] y[2]]Define a numerical constant equal to
:
N[pit] := N[Pi / 2]In an exact symbolic expression, the constant does not evaluate:
Sin[pit]With N, it does:
N[%]Add a definition that will work with arbitrary precision or accuracy:
N[pit, pa_] := N[Pi / 2, pa]Numerically evaluate an expression to accuracy 20:
N[π - 2 pit, {∞, 20}]Define a function that represents the real-valued root
for positive
and positive integer
:
nthroot[x_ ? InexactNumberQ /; Positive[x], n_Integer /; Positive[n]] := FixedPoint[((n - 1) # ^ n + x) / (n # ^ (n - 1))&, N[1, Precision[x]]]Prevent its second argument from being converted to real using NHoldRest:
SetAttributes[nthroot, NHoldRest]An exact representation of the cube root of 2:
crt = nthroot[2, 3]N[crt]N[crt, 47]Define a data object that represents a polynomial
in a sparse form
:
spoly[cp_][x_] := Module[{c, n, p, y},
{p, c} = Transpose[SortBy[cp, Last]];
n = p[[-1]];
y = c[[-1]];
Do[y = c[[k]] + x ^ (n - p[[k]]) * y;n = p[[k]], {k, Length[p] - 1, 1, -1}];
If[n > 0, y *= x ^ n];
y]Make sure that N only affects the coefficients, not the powers:
N[e : spoly[cp_], pa_] := Module[{p, c, nc},
{c, p} = Transpose[cp];
nc = N[c, pa];
If[nc === c, e, spoly[Transpose[{nc, p}]]]]Default N evaluation of the argument needs to be prevented for the rule to work:
SetAttributes[spoly, NHoldAll]A representation of the polynomial
:
sp = spoly[{{1, 1}, {2, 2}, {3, 4}, {4, 8}}]{sp[x], Expand[sp[x]]}Get the representation with approximate real coefficients:
nsp = N[sp]nsp[π]Generalizations & Extensions (3)
5-digit accuracy and any precision:
N[Pi ^ 10, {Infinity, 5}]1-digit accuracy, corresponding to integer part only:
N[Pi ^ 10, {Infinity, 1}]Get either 20-digit precision or 30-digit accuracy:
val = N[1 - Sqrt[1 + Exp[-1000]], {20, 30}]{Accuracy[val], Precision[val]}Properties & Relations (3)
The result of N[e] generally has precision MachinePrecision:
N[Exp[Sin[1000]]]Precision[%]If the result is too large for machine numbers, the precision may be different:
ne = N[Exp[1000]]Precision[%]The result of N[e,p] generally has Precision equal to p:
N[Exp[Sin[1000]], 47]Precision[%]When this is not possible, the Wolfram Language will give a message:
N[1 - Sqrt[1 - Exp[-1000]], 20]Typically, increasing $MaxExtraPrecision will resolve the problem:
Block[{$MaxExtraPrecision = 500}, N[1 - Sqrt[1 - Exp[-1000]], 20]]Precision[%]For hidden zeros, positive precision is not achievable, so you may want to use accuracy:
N[1 / GoldenRatio + 1 - GoldenRatio, 20]N[1 / GoldenRatio + 1 - GoldenRatio, {∞, 20}]Accuracy[%]The result of N[e,{∞,a}] generally has Accuracy equal to a:
N[Exp[100], {∞, -10}]Accuracy[%]When this is not possible, the Wolfram Language will give a message:
N[10000000000(Exp[100] - Exp[999999999999 / 10000000000]), {∞, 20}]Typically, increasing $MaxExtraPrecision will resolve the problem:
Block[{$MaxExtraPrecision = 200}, N[10000000000(Exp[100] - Exp[999999999999 / 10000000000]), {∞, 20}]]Accuracy[%]Related Guides
History
Introduced in 1988 (1.0) | Updated in 1996 (3.0) ▪ 1999 (4.0) ▪ 2003 (5.0)
Text
Wolfram Research (1988), N, Wolfram Language function, https://reference.wolfram.com/language/ref/N.html (updated 2003).
CMS
Wolfram Language. 1988. "N." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2003. https://reference.wolfram.com/language/ref/N.html.
APA
Wolfram Language. (1988). N. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/N.html
BibTeX
@misc{reference.wolfram_2026_n, author="Wolfram Research", title="{N}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/N.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_n, organization={Wolfram Research}, title={N}, year={2003}, url={https://reference.wolfram.com/language/ref/N.html}, note=[Accessed: 12-June-2026]}