NumericQ

NumericQ[expr]

gives True if expr is a numeric quantity, and False otherwise.

Details

  • An expression is considered a numeric quantity if it is either an explicit number or a mathematical constant such as Pi, or is a function that has attribute NumericFunction and all of whose arguments are numeric quantities.
  • In most cases, NumericQ[expr] gives True whenever N[expr] would yield an explicit number.

Examples

open allclose all

Basic Examples  (1)

NumericQ tests whether an object is a numeric quantity:

In most cases, NumericQ[expr] gives True whenever N[expr] yields an explicit number:

Scope  (3)

An object is numeric if all its constituents are numeric:

Some parts of the expression are numeric:

When f has the NumericFunction attribute then f[args] is numeric when args are numeric:

The system symbols that represent numerical constants:

The system symbols with the NumericFunction attribute:

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

In most cases, N[e] will not be a number since it is improbable that the arguments are correct:

Applications  (3)

Test if a matrix consists of numeric entries:

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

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

Possible Issues  (1)

NumericQ[e] does not always imply that N[e] will yield a number:

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

Introduced in 1996
 (3.0)