[R] Fortran and long integers

Tsjerk Wassenaar tsjerkw at gmail.com
Mon Feb 7 08:09:08 CET 2011


Hi,

Does it alleviate things if you rewrite the sums to avoid large products?

For I even:
J+I*(N-I/2)-(N-I/2)

For I odd:
J+I*(N-(I+1)/2)-(N-(I+1)/2)+(I+1)/2

Hope it helps,

Tsjerk


On Mon, Feb 7, 2011 at 7:21 AM, Berend Hasselman <bhh at xs4all.nl> wrote:
>
>
> Earl F Glynn wrote:
>>
>>
>> 2-byte (16 bit) signed integers would have a range from -32768 to
>> +37267.  So, it looks like you may be using 2-byte integers and 46,300
>> would definitely cause an overflow with 16-bit integers.
>>
>> I haven't used Fortran for a long time, but there could be a compiler
>> switch that forces all 2-byte integers, or a specific declaration that
>> says I, J, N, IOFFSET are only 2-byte (16-bit) integers.
>>
>> I'm guess, but you might try a specification like
>>
>>    INTEGER*4 I, J, N, IOFFSET
>>
>> assuming INTEGER*4 is legal with your Fortran compiler:
>>
>
> The overflow is not caused by 16 bits integers.
> I'm quite sure the OP is using 32 bit integers.
> The overflow is caused by  the multiplication N*(i-1) and/or i*(i+1).
>
> In Fortran there's not much you can do about this unless your compiler
> supports larger integers.
> A pity that fortran doesn't have a posint.
>
> Either your solution with doubles or a small C function looks like the way
> out.
>
> Berend
> --
> View this message in context: http://r.789695.n4.nabble.com/Fortran-and-long-integers-tp3263054p3263605.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands



More information about the R-help mailing list