Nathalie Jarosz wrote:
Hello everybody!
As I already have had a problem with compilation under unix, I would like to know if this following error is something related to or something else: bathy.p: In function `Principal': bathy.p:977: constant out of range
The line in question is: for ii:=1 to nsites do begin larves[ii]:=round(0.7*pop_max*fec*sex*ferti);
and the constant: const r = 1000000; pop_max = 750000; max = 10000; sex = 0.5; fec = 1000000; ferti = 0.8;
I don't really understand because if I run a little program only with these lines, it works, but not in the whole program.
Please, when reporting bugs, always post *complete* test programs. Otherwise, we have incomplete information and can only guess.
The following "little program only with these lines" gives the same error message on my system. That's correct since the value of the constant is larger than MaxInt (2^31-1), and therefore cannot be stored in an integer (if you're on a 64 bit system, it might work).
If you declare larves as `LongInt' which has a larger range than `Integer' (-2^63 .. 2^63-1), it should work. If that's still not enough for you, you can look at the GMP unit...
program foo; const r = 1000000; pop_max = 750000; max = 10000; sex = 0.5; fec = 1000000; ferti = 0.8; nsites = 10;
var ii : Integer; larves : array [1 .. nsites] of Integer;
begin for ii:=1 to nsites do larves[ii]:=round(0.7*pop_max*fec*sex*ferti); end.
Frank
Frank Heckenbach wrote:
const r = 1000000; pop_max = 750000; max = 10000; sex = 0.5; fec = 1000000; ferti = 0.8;
If you declare larves as `LongInt' which has a larger range than `Integer' (-2^63 .. 2^63-1), it should work. If that's still not enough for you, you can look at the GMP unit...
Depending on what you are doing, some of your "integer" constants might also be `Real's. When that's the case for one of the constants, just add `.0' to the declaration, e.g.:
const r = 1000000.0;
Calculations with `Real' numbers are not exact but approximated by the CPU, and you cannot "count" with them. But they can be much larger (or much closer to zero while still nonzero) than `Integer' numbers.
Hope this helps,
Peter