Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

double: Double-Precision Vectors

doubleR Documentation

Double-Precision Vectors

Description

Create, coerce to or test for a double-precision vector.

Usage

double(length = 0)as.double(x, ...)is.double(x)single(length = 0)as.single(x, ...)

Arguments

length

A non-negative integer specifying the desired length.Double values will be coerced to integer:supplying an argument of length other than one is an error.

x

object to be coerced or tested.

...

further arguments passed to or from other methods.

Details

double creates a double-precision vector of the specifiedlength. The elements of the vector are all equal to0.It is identical tonumeric.

as.double is a generic function. It is identical toas.numeric. Methods should return an object of base type"double".

is.double is a test of double type.

R has no single precision data type. All real numbers arestored in double precision format. The functionsas.singleandsingle are identical toas.double anddoubleexcept they set the attributeCsingle that is used in the.C and.Fortran interface, and they areintended only to be used in that context.

Value

double creates a double-precision vector of the specifiedlength. The elements of the vector are all equal to0.

as.double attempts to coerce its argument to be of double type:likeas.vector it strips attributes including names.(To ensure that an object is of double type without strippingattributes, usestorage.mode.) Character stringscontaining optional whitespace followed by either a decimalrepresentation or a hexadecimal representation (starting with0x or0X) can be converted, as can special values suchas"NA","NaN","Inf" and"infinity",irrespective of case.

as.double for factors yields the codes underlying the factorlevels, not the numeric representation of the labels, see alsofactor.

is.double returnsTRUE orFALSE depending onwhether its argument is of double type or not.

Double-precision values

AllR platforms are required to work with values conforming to theIEC 60559 (also known as IEEE 754) standard. This basically workswith a precision of 53 bits, and represents to that precision a rangeof absolute values from about2e-308 to2e+308. It also has special valuesNaN (many of them), plus and minus infinity and plus andminus zero (althoughR acts as if these are the same). There arealsodenormal(ized) (orsubnormal) numbers with absolutevalues above or below the range given above but represented to lessprecision.

See.Machine for precise information on these limits.Note that ultimately how double precision numbers are handled is downto the CPU/FPU and compiler.

In IEEE 754-2008/IEC60559:2011 this is called ‘binary64’ format.

Note on names

It is a historical anomaly thatR has two names for itsfloating-point vectors,double andnumeric(and formerly hadreal).

double is the name of the type.numeric is the name of the mode and also of the implicitclass. As an S4 formal class, use"numeric".

The potential confusion is thatR has usedmode"numeric" to mean ‘double or integer’, which conflictswith the S4 usage. Thusis.numeric tests the mode, not theclass, butas.numeric (which is identical toas.double)coerces to the class.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.

https://en.wikipedia.org/wiki/IEEE_754-1985,https://en.wikipedia.org/wiki/IEEE_754-2008,https://en.wikipedia.org/wiki/IEEE_754-2019,https://en.wikipedia.org/wiki/Double_precision,https://en.wikipedia.org/wiki/Denormal_number.

See Also

integer,numeric,storage.mode.

Examples

is.double(1)all(double(3) == 0)

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp