\HeaderA{NumericConstants}{Numeric Constants}{NumericConstants}
\keyword{documentation}{NumericConstants}
\begin{Description}\relax
How \R{} parses numeric constants.
\end{Description}
\begin{Details}\relax
\R{} parses numeric constants in its input in a very similar way to C99
floating-point constants.

\code{\LinkA{Inf}{Inf}} and \code{\LinkA{NaN}{NaN}} are numeric constants (with
\code{\LinkA{typeof}{typeof}(.) "double"}).  These are recognized ignoring case,
as is \code{infinity} as an alternative to \code{Inf}.
\code{\LinkA{NA\_real\_}{NA.Rul.real.Rul.}} and \code{\LinkA{NA\_integer\_}{NA.Rul.integer.Rul.}} are constants of
types \code{"double"} and \code{"integer"} representing missing
values.  All other numeric constants start with a digit or period and
are either a decimal or hexadecimal constant optionally followed by
\code{L}.

Hexadecimal constants start with \code{0x} or \code{0X} followed by
a nonempty sequence from \code{0-9 a-f A-F} which is interpreted as a
hexadecimal number, optionally followed by a binary exponent.  A binary
exponent consists of an \code{P} or \code{p} followed by an optional
plus or minus sign followed by a non-empty sequence of (decimal)
digits, and indicates multiplication by a power of two.  Thus
\code{0x123p456} is \eqn{291 \times 2^{456}}{291 * 2^456}.

Decimal constants consist of a nonempty sequence of digits possibly
containing a period (the decimal point), optionally followed by a
decimal exponent.  A decimal exponent consists of an \code{E} or
\code{e} followed by an optional plus or minus sign followed by a
non-empty sequence of digits, and indicates multiplication by a power
of ten.

Values which are too large or too small to be representable will
overflow to \code{Inf} or underflow to \code{0.0}.

A numeric constant immediately followed by \code{i} is regarded as an
imaginary \LinkA{complex}{complex} number.

An numeric constant immediately followed by \code{L} is regarded as an
\code{\LinkA{integer}{integer}} number when possible (and with a warning if it
contains a \code{"."}).

Only the ASCII digits 0--9 are recognized as digits, even in languages
which have other representations of digits.  The \sQuote{decimal
separator} is always a period and never a comma.

Note that a leading plus or minus is not regarded by the parser as
part of a numeric constant but as a unary operator applied to the constant.
\end{Details}
\begin{SeeAlso}\relax
\code{\LinkA{Syntax}{Syntax}}.

\code{\LinkA{Quotes}{Quotes}} for the parsing of character constants,
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
2.1
typeof(2)
sqrt(1i) # remember elementary math?
utils::str(0xA0)
identical(1L, as.integer(1))

## You can combine the "0x" prefix with the "L" suffix :
identical(0xFL, as.integer(15)) # (with a regard to Fritz :-)
\end{ExampleCode}
\end{Examples}

