double(length=0) is.double(x) as.double(x)
double
returns a simple object of storage mode
"double"
, and the
length specified.
is.double
returns
TRUE
if
x
is an object of storage mode
"double"
. Otherwise, it returns
FALSE
.
as.double
returns
x
if
x
is a simple object of storage mode
"double"
. Otherwise, it returns a vector or
bdVector
of the same length as
x
and with data resulting
from coercing the elements of
x
to storage mode
double
.
The
is.double
function is generic and has a method for
"factor"
(which returns
FALSE
).
If you want a factor to be treated as numeric, use
codes
.
These functions are needed when interfacing
to Fortran or C algorithms, where it is important to emphasize the exact
storage mode of data.
In most S-PLUS expressions it is not
necessary to explicitly ensure that data are of a particular storage mode.
When testing for data suitable for arithmetic, for example, it is better to
use
is.numeric(x)
,
which will return
TRUE
for any numeric or
bdNumeric
object.
Normally, S-PLUS does numeric computations with double precision.
Explicit reference to storage mode
double
is usually only
relevant when passing arguments to Fortran or C routines that
have arguments with double precision or float declarations.
Note the difference between coercing to a vector or
bdVector
and setting the storage mode attribute:
storage.mode(myobject) <- "double"
This changes the storage mode of
myobject
but leaves all other attributes unchanged
(so, e.g., a matrix stays a matrix). The value of
as.double(myobject)
has no attributes.
z <- double(length(zz)) # double object same length as zz .Fortran("mydsub",as.double(xm))