NumberQ¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
NumberQ[expr]
gives True if expr is an explicit number (Integer, BigInt, Rational, Real, MPFR, or Complex), and False otherwise. Symbolic constants such as Pi give False; use NumericQ for those.
Examples (15)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (4)¶
In[1]:= StringQ["AbC"]
Out[1]= True
In[2]:= StringQ[""]
Out[2]= True
In[3]:= StringQ[123]
Out[3]= False
In[4]:= StringQ[] StringQ::argx: StringQ called with 0 arguments; 1 argument is expected.
Scope (6)¶
Overflows to +inf
MPFR, not machine
Exact Gaussian integer
Applications (5)¶
In[11]:= NumberQ[3]
Out[11]= True
In[12]:= NumberQ[2/3]
Out[12]= True
In[13]:= NumberQ[1 + 2 I]
Out[13]= True
A symbolic constant is not an explicit number
Implementation notes¶
builtin_numberq (src/core.c) returns True for an explicit number ā EXPR_INTEGER, EXPR_REAL, EXPR_BIGINT, EXPR_MPFR (under USE_MPFR), or a Rational/Complex head ā and False otherwise. (Contrast NumericQ, whose is_numeric_quantity helper also accepts symbolic constants like Pi and numeric-function calls.)
Attributes: Protected.
References¶
See also: AtomQ, IntegerQ, StringQ, MachineNumberQ, Complex, ExactNumberQ
- Source:
src/core.c - Specification:
docs/spec/builtins/expression-information.md - Tests:
tests/test_accuracygoal.c - Tests:
tests/test_autocompile.c - Tests:
tests/test_bigint.c - Tests:
tests/test_core.c
Notes & additional examples¶
Notes¶
NumberQ[expr] is True for an explicit number ā an integer, bigint, machine
or arbitrary-precision real, rational, or complex. It draws the line exactly where
NumericQ does not: NumberQ[Pi] is False because Pi is a symbol that merely
has a numeric value, whereas NumericQ[Pi] is True. Use NumberQ when you
need an already-evaluated literal number, and NumericQ when a symbolic constant
or a numeric-function call should also qualify.