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

Romain Francois romain at r-enthusiasts.com
Tue Apr 6 18:27:33 CEST 2010


Le 06/04/10 15:46, Douglas Bates a écrit :
> On Tue, Apr 6, 2010 at 8:40 AM, Romain Francois
> <romain at r-enthusiasts.com>  wrote:
>> Le 06/04/10 15:32, Dirk Eddelbuettel a écrit :
>>>
>>> On 6 April 2010 at 14:27, Romain Francois wrote:
>>> |>    Perhaps I am not answering the question that you asked - that sort of
>>> |>    thing happens when answering email while still on the first cup of
>>> |>    coffee.  More helpful might be the comments in the limits include file
>>> |>    for libstdc++ on Debian/Ubuntu
>>> |>
>>> |>    // The numeric_limits<>     traits document implementation-defined
>>> aspects
>>> |>    // of fundamental arithmetic data types (integers and floating
>>> points).
>>> |>    // From Standard C++ point of view, there are 13 such types:
>>> |>    //   * integers
>>> |>    //         bool
>>> (1)
>>> |>    //         char, signed char, unsigned char                 (3)
>>> |>    //         short, unsigned short                            (2)
>>> |>    //         int, unsigned                                    (2)
>>> |>    //         long, unsigned long
>>>   (2)
>>> |>    //
>>> |>    //   * floating points
>>> |>    //         float                                            (1)
>>> |>    //         double                                           (1)
>>> |>    //         long double
>>>   (1)
>>> |>    //
>>> |>    // GNU C++ understands (where supported by the host C-library)
>>> |>    //   * integer
>>> |>    //         long long, unsigned long long                    (2)
>>> |>    //
>>> |>    // which brings us to 15 fundamental arithmetic data types in GNU C++.
>>> |>
>>> |>    So it looks like short is part of standard C++ but not long long.
>>> |
>>> | Even better, thanks again.
>>>
>>> Not to beat a dead horse (and yours, at that) but the long long and
>>> unsigned
>>> long long are hence not portable but GNU g++ dependent.
>>
>> I have not touched long long and unsigned long long so we are still in
>> standard c++.
>>
>> If I do them, they will be hidden in #ifdef __GNUC__
>
> What do you plan to do about wrapping a std::vector<long double>?
> There is no corresponding data type in R.  With something like long
> long you can map to a double which takes most of the range without
> round-off but a long double will either be truncated by mapping to a
> double or will need some crafty construction in R.

I should have said sorry. I cast to the "most acceptable" type :

short          -> INTSXP
long           -> REALSXP
long double    -> REALSXP
unsigned short -> INTSXP
unsigned long  -> REALSXP

This is similar to what rJava does with similar java primitive types.

Some precision is lost, but I find this more acceptable than the crytpic 
error messages you'd get otherwise. This of course will need some 
documentation.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/9aKDM9 : embed images in Rd documents
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7



More information about the Rcpp-devel mailing list