Rev 52927 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/NumericConstants.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2010 R Core Development Team% Distributed under GPL 2 or later\name{NumericConstants}\alias{NumericConstants}\alias{1L}\alias{0x1}\alias{1i}\title{Numeric Constants}\description{How \R parses numeric constants.}\details{\R parses numeric constants in its input in a very similar way to C99floating-point constants.\code{\link{Inf}} and \code{\link{NaN}} are numeric constants (with\code{\link{typeof}(.) "double"}). These are recognized ignoring case,as is \code{infinity} as an alternative to \code{Inf}.\code{\link{NA_real_}} and \code{\link{NA_integer_}} are constants oftypes \code{"double"} and \code{"integer"} representing missingvalues. All other numeric constants start with a digit or period andare either a decimal or hexadecimal constant optionally followed by\code{L}.Hexadecimal constants start with \code{0x} or \code{0X} followed bya nonempty sequence from \code{0-9 a-f A-F .} which is interpreted as ahexadecimal number, optionally followed by a binary exponent. A binaryexponent consists of a \code{P} or \code{p} followed by an optionalplus 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 possiblycontaining a period (the decimal point), optionally followed by adecimal exponent. A decimal exponent consists of an \code{E} or\code{e} followed by an optional plus or minus sign followed by anon-empty sequence of digits, and indicates multiplication by a powerof ten.Values which are too large or too small to be representable willoverflow to \code{Inf} or underflow to \code{0.0}.A numeric constant immediately followed by \code{i} is regarded as animaginary \link{complex} number.An numeric constant immediately followed by \code{L} is regarded as an\code{\link{integer}} number when possible (and with a warning if itcontains a \code{"."}).Only the ASCII digits 0--9 are recognized as digits, even in languageswhich have other representations of digits. The \sQuote{decimalseparator} is always a period and never a comma.Note that a leading plus or minus is not regarded by the parser aspart of a numeric constant but as a unary operator applied to the constant.}\note{When a string is parsed to input a numeric constant, the number may ormay not be representable exactly in the C double type used. If notone of the nearest representable numbers will be returned.\R's own C code is used to convert constants to binary numbers, so theeffect can be expected to be the same on all platforms implementingfull IEC 600559 arithmetic (the most likely area of difference beingthe handling of numbers less than \code{\link{.Machine}$double.xmin}).The same code is used by \code{\link{scan}}. } \seealso{\code{\link{Syntax}}.\code{\link{Quotes}} for the parsing of character constants,}\examples{2.1typeof(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))}\keyword{documentation}