Movatterモバイル変換


[0]ホーム

URL:


NumericConstants {base}R Documentation

Numeric Constants

Description

HowR parses numeric constants.

Details

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

Inf andNaN are numeric constants (withtypeof(.) "double"). In text input (e.g., inscan andas.double), these are recognizedignoring case as isinfinity as an alternative toInf.NA_real_ andNA_integer_ are constants oftypes"double" and"integer" representing missingvalues. All other numeric constants start with a digit or period andare either a decimal or hexadecimal constant optionally followed byL.

Hexadecimal constants start with0x or0X followed bya non-empty sequence from0-9 a-f A-F . which is interpreted as ahexadecimal number, optionally followed by a binary exponent. A binaryexponent consists of aP orp followed by an optionalplus or minus sign followed by a non-empty sequence of (decimal)digits, and indicates multiplication by a power of two. Thus0x123p456 is291 \times 2^{456}.

Decimal constants consist of a non-empty sequence of digits possiblycontaining a period (the decimal point), optionally followed by adecimal exponent. A decimal exponent consists of anE ore 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 toInf or underflow to0.0.

A numeric constant immediately followed byi is regarded as animaginarycomplex number.

A numeric constant immediately followed byL is regarded as aninteger number when possible (and with a warning if itcontains a".").

Only the ASCII digits 0–9 are recognized as digits, even in languageswhich have other representations of digits. The ‘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 implementingfullIEC 60559 arithmetic (the most likely area of difference beingthe handling of numbers less than.Machine$double.xmin).The same code is used byscan.

See Also

Syntax.For complex numbers, seecomplex.Quotes for the parsing of character constants,Reserved for the “reserved words” inR.

Examples

## You can create numbers using fixed or scientific formatting.2.12.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 identical2 == 2Lidentical(2, 2L)## You can write numbers between 0 and 1 without a leading "0"## (but typically this makes code harder to read).1234sqrt(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))

[Packagebase version 4.6.0Index]

[8]ページ先頭

©2009-2025 Movatter.jp