EVOLUTION-MANAGER
Edit File: NumericConstants.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Numeric Constants</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for NumericConstants {base}"><tr><td>NumericConstants {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Numeric Constants</h2> <h3>Description</h3> <p>How <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> parses numeric constants. </p> <h3>Details</h3> <p><span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> parses numeric constants in its input in a very similar way to C99 floating-point constants. </p> <p><code><a href="is.finite.html">Inf</a></code> and <code><a href="is.finite.html">NaN</a></code> are numeric constants (with <code><a href="typeof.html">typeof</a>(.) "double"</code>). In text input (e.g., in <code><a href="scan.html">scan</a></code> and <code><a href="double.html">as.double</a></code>), these are recognized ignoring case as is <code>infinity</code> as an alternative to <code>Inf</code>. <code><a href="NA.html">NA_real_</a></code> and <code><a href="NA.html">NA_integer_</a></code> are constants of types <code>"double"</code> and <code>"integer"</code> 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</code>. </p> <p>Hexadecimal constants start with <code>0x</code> or <code>0X</code> followed by a nonempty sequence from <code>0-9 a-f A-F .</code> which is interpreted as a hexadecimal number, optionally followed by a binary exponent. A binary exponent consists of a <code>P</code> or <code>p</code> 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</code> is <i>291 * 2^456</i>. </p> <p>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</code> or <code>e</code> followed by an optional plus or minus sign followed by a non-empty sequence of digits, and indicates multiplication by a power of ten. </p> <p>Values which are too large or too small to be representable will overflow to <code>Inf</code> or underflow to <code>0.0</code>. </p> <p>A numeric constant immediately followed by <code>i</code> is regarded as an imaginary <a href="complex.html">complex</a> number. </p> <p>An numeric constant immediately followed by <code>L</code> is regarded as an <code><a href="integer.html">integer</a></code> number when possible (and with a warning if it contains a <code>"."</code>). </p> <p>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. </p> <p>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. </p> <h3>Note</h3> <p>When a string is parsed to input a numeric constant, the number may or may not be representable exactly in the C double type used. If not one of the nearest representable numbers will be returned. </p> <p><span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>'s own C code is used to convert constants to binary numbers, so the effect can be expected to be the same on all platforms implementing full IEC 600559 arithmetic (the most likely area of difference being the handling of numbers less than <code><a href="zMachine.html">.Machine</a>$double.xmin</code>). The same code is used by <code><a href="scan.html">scan</a></code>. </p> <h3>See Also</h3> <p><code><a href="Syntax.html">Syntax</a></code>. For complex numbers, see <code><a href="complex.html">complex</a></code>. <code><a href="Quotes.html">Quotes</a></code> for the parsing of character constants, <code><a href="Reserved.html">Reserved</a></code> for the “reserved words” in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>. </p> <h3>Examples</h3> <pre> ## 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) .1234 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)) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>