[Rcpp-devel] short, unsigned short, long, unsigned long, long double

Douglas Bates bates at stat.wisc.edu
Tue Apr 6 14:15:05 CEST 2010


On Tue, Apr 6, 2010 at 6:54 AM, Romain Francois
<romain at r-enthusiasts.com> wrote:
> Hello,
>
> I have added support for these primitive types in Rcpp, so that one can
> wrap containers such as :
>
> std::vector<short>, ...
>
> Is this something that should be protected in case there is no "short",
> "long", etc ?

You can check in R's .Machine object on the various sizes for which R
scans.  It can tell you if there is a difference between long and long
long or between double and long double.  It does not list anything
regarding short.  The sum of double.digits and double.exponent is the
number of bits in a double.  Generally log(.Machine$integer.max, 2) is
1 less than the number of bits in an int.


> str(.Machine)
List of 18
 $ double.eps           : num 2.22e-16
 $ double.neg.eps       : num 1.11e-16
 $ double.xmin          : num 2.23e-308
 $ double.xmax          : num 1.80e+308
 $ double.base          : int 2
 $ double.digits        : int 53
 $ double.rounding      : int 5
 $ double.guard         : int 0
 $ double.ulp.digits    : int -52
 $ double.neg.ulp.digits: int -53
 $ double.exponent      : int 11
 $ double.min.exp       : int -1022
 $ double.max.exp       : int 1024
 $ integer.max          : int 2147483647
 $ sizeof.long          : int 4
 $ sizeof.longlong      : int 8
 $ sizeof.longdouble    : int 12
 $ sizeof.pointer       : int 4
> log(.Machine$integer.max, 2)
[1] 31


More information about the Rcpp-devel mailing list