Dear Prof. Ripley,

Once again, thank you for your replies.
I must confess not being a genuine C programmer, having learned how to use
C only in connection to R (and the macros provided are almost a separate
language to learn).

I'll try to read more about the types you've indicated, and will keep
trying. So far, most certainly I am not doing it right, because all of them
have the same result. Tried declaring:

uint64_t power[lgth];
and
uint_fast64_t power[lgth];
and
uintmax_t power[lgth];

but still the top threshold appears at the limit of 32-bit in all cases.

Will keep reading about these...
Best wishes,
Adrian



On Wed, May 14, 2014 at 2:45 PM, Prof Brian Ripley <rip...@stats.ox.ac.uk>wrote:

> On 14/05/2014 10:37, Adrian Dușa wrote:
>
>> Dear devels,
>>
>> I need to create a (short) vector in C, which contains potentially very
>> large numbers, exponentially to the powers of 2.
>>
>
> This isn't an R question, except in so far that R mandates the usual
> convention of C <int> being 32-bit.  However
>
> 1) You should use an unsigned integer type.
> 2) Most compilers have uint64_t but C99/C11 do not require it.  They
> require uint_fast64_t and uintmax_t (which is the widest unsigned int)
> types.
> 3) double will hold much larger powers, and functions like pow_di (where
> supported) or pow will compute them efficiently for you.  And R has
> R_pow_di in Rmath.h.
>
>
>
>> This is my test example:
>>
>> lgth = 35;
>> int power[lgth];
>> power[lgth - 1] = 1;
>> for (j = 1; j < lgth; j++) {
>>      power[lgth - j - 1] = 2*power[lgth - j];
>> }
>>
>> Everything works ok until it reaches the limit of 2^32:
>>
>> power: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192,
>> 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304,
>> 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912,
>> 1073741824, -2147483648, 0, 0, 0
>>
>> How should I declare the "power" vector, in order to accept integer values
>> larger then 2^32?
>>
>> Thanks very much in advance,
>> Adrian
>>
>>
>>
>
> --
> Brian D. Ripley,                  rip...@stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
        +40 21 3120210 / int.101
Fax: +40 21 3158391

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to