[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  NumericConstants: Numeric Constants

##  Description

How  R  parses numeric constants.

##  Arguments

##  Details

R  parses numeric constants in its input in a very similar way to C99
floating-point constants.

` [ Inf ](/link/Inf?package=base&version=3.6.2) ` and ` [ NaN
](/link/NaN?package=base&version=3.6.2) ` are numeric constants (with ` [
typeof ](/link/typeof?package=base&version=3.6.2) (.) "double" ` ). In text
input (e.g., in ` [ scan ](/link/scan?package=base&version=3.6.2) ` and ` [
as.double ](/link/as.double?package=base&version=3.6.2) ` ), these are
recognized ignoring case as is ` infinity ` as an alternative to ` Inf ` . ` [
NA_real_ ](/link/NA_real_?package=base&version=3.6.2) ` and ` [ NA_integer_
](/link/NA_integer_?package=base&version=3.6.2) ` are constants of types `
"double" ` and ` "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 ` L ` .

Hexadecimal constants start with ` 0x ` or ` 0X ` followed by a nonempty
sequence from ` 0-9 a-f A-F . ` which is interpreted as a hexadecimal number,
optionally followed by a binary exponent. A binary exponent consists of a ` P
` or ` 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 ` 0x123p456 ` is \\(291 \times 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 ` E ` or ` 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 `
Inf ` or underflow to ` 0.0 ` .

A numeric constant immediately followed by ` i ` is regarded as an imaginary [
complex ](/link/complex?package=base&version=3.6.2) number.

An numeric constant immediately followed by ` L ` is regarded as an ` [
integer ](/link/integer?package=base&version=3.6.2) ` number when possible
(and with a warning if it contains a ` "." ` ).

Only the ASCII digits 0--9 are recognized as digits, even in languages which
have other representations of digits. The ‘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.

##  See Also

` [ Syntax ](/link/Syntax?package=base&version=3.6.2) ` . For complex numbers,
see ` [ complex ](/link/complex?package=base&version=3.6.2) ` . ` [ Quotes
](/link/Quotes?package=base&version=3.6.2) ` for the parsing of character
constants, ` [ Reserved ](/link/Reserved?package=base&version=3.6.2) ` for the
“reserved words” in  R  .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2FNumericConstants&utm_source=r-docs&utm_medium=docs&utm_term=NumericConstants&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    ## You can create numbers using fixed or scientific formatting.
    2.1
    2.1e10
    -2.1E-10
    
    ## The resulting objects have class numeric and type double.
    class(2.1)
    typeof(2.1)
    
    ## This holds even if what you typed looked like an integer.
    class(2)
    typeof(2)
    
    ## If you actually wanted integers, use an "L" suffix.
    class(2L)
    typeof(2L)
    
    ## These are equal but not identical
    2 == 2L
    identical(2, 2L)
    
    ## You can write numbers between 0 and 1 without a leading "0"
    ## (but typically this makes code harder to read)
    .