({{, (RefLink[NumericQ, paclet:ref/NumericQ])[expr]
gives (RefLink[True, paclet:ref/True]) if expr is a numeric quantity, and (RefLink[False, paclet:ref/False]) otherwise. }})

OpenersNotesSection(Spacer1)Details

An expression is considered a numeric quantity if it is either an explicit number or a mathematical constant such as (RefLink[Pi, paclet:ref/Pi]), or is a function that has attribute (RefLink[NumericFunction, paclet:ref/NumericFunction]) and all of whose arguments are numeric quantities.

In most cases, (RefLink[NumericQ, paclet:ref/NumericQ])[expr] gives (RefLink[True, paclet:ref/True]) whenever (RefLink[N, paclet:ref/N])[expr] would yield an explicit number.

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

(RefLink[NumericQ, paclet:ref/NumericQ]) tests whether an object is a numeric quantity:

NumericQ[Sin[Sqrt[2]]]

In most cases, (RefLink[NumericQ, paclet:ref/NumericQ])[expr] gives (RefLink[True, paclet:ref/True]) whenever (RefLink[N, paclet:ref/N])[expr] yields an explicit number:

N[Sin[Sqrt[2]]]

OpenersExampleSection1(Spacer1)Scope  (3)

An object is numeric if all its constituents are numeric:

expr=BesselJ[2,Sin[Exp[Log[3]+4]] + x];

NumericQ[expr]

Some parts of the expression are numeric:

TableForm[Map[{#,NumericQ[#]}&,Level[expr,{0,Infinity}]],TableHeadings->{{},{"e","NumericQ[e]"}}]

When f has the (RefLink[NumericFunction, paclet:ref/NumericFunction]) attribute then f[args] is numeric when args are numeric:

SetAttributes[f,NumericFunction]

NumericQ[f[Pi,Sin[1+I]]]

The system symbols that represent numerical constants:

ssymb=Names["System`*"];

constants=Select[ssymb,MemberQ[Attributes[#],Constant]&]

The system symbols with the (RefLink[NumericFunction, paclet:ref/NumericFunction]) attribute:

nfuns=Select[ssymb,MemberQ[Attributes[#],NumericFunction]&]

Any combination of these functions with numeric arguments will be numeric:

e=Quiet[Nest[RandomChoice[ToExpression@nfuns][RandomChoice[ToExpression@constants],#]&,1,10]]

NumericQ[e]

In most cases, (RefLink[N, paclet:ref/N])[e] will not be a number since it is improbable that the arguments are correct:

NumberQ[Quiet[N[e]]]

OpenersExampleSection2(Spacer1)Applications  (3)

Test if a matrix consists of numeric entries:

m={{Cos[1],Sin[1]},{-Sin[1],Cos[1]}};

MatrixQ[m,NumericQ]

Define a function that only evaluates when its argument is numeric:

f[a_?NumericQ]:=Module[{g,x},Quiet[g[x_]=x^2+x+a;r=x/.FindRoot[g[x],{x,1}];If[Abs[g[r]]<10^-4,r,x/.FindRoot[g[x],{x,1+I}]]]]

f[a]

f[Sqrt[2]]

Plot[{Re[f[a]],Im[f[a]]},{a,-2,2}]

Define a function that has a special case for numeric arguments:

f[x_?NumericQ,prec_:MachinePrecision]:=N[x,prec]

f[x_]:=FullSimplify[x]

f[Exp[1]+Exp[-1]]

f[Exp[x]+Exp[-x]]

OpenersExampleSection3(Spacer1)Possible Issues  (1)

(RefLink[NumericQ, paclet:ref/NumericQ])[e] does not always imply that (RefLink[N, paclet:ref/N])[e] will yield a number:

e=1/(Sin[1]^2+Cos[1]^2-1)

NumericQ[e]

SetPrecision[e,20]

NumberQ[%]

This can also happen when the arguments for the function are given incorrectly:

e=Sin[1,2]

NumericQ[e]

NumberQ[N[e]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NumberQ, paclet:ref/NumberQ])  ▪  (RefLink[NumericFunction, paclet:ref/NumericFunction])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Putting Constraints on Patterns, paclet:tutorial/PuttingConstraintsOnPatterns])}, {▪(RefLinkPlain[Numeric Quantities, paclet:tutorial/NumericQuantities])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Testing Expressions, paclet:guide/TestingExpressions])}})}})