[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: wierd random number behavior
From: |
Benedikt Stefansson |
Subject: |
Re: wierd random number behavior |
Date: |
Tue, 20 Apr 1999 16:18:31 +0200 |
Sirs,
Before further research into compilers and processor types, I was
wondering if Paul could fix some potential syntax errors in the
offending method which started this thread. Since Paul didn't include
the full source code I can't replicate the situation, would need to know
what type and value the instance variables "urgency","load" and
"moisture" take.
Note the exp() function call here:
threshold = urgency * load * exp(-moisture / 4);
On Linux I've had problems when dividing a floating point value by an
integer (i.e using 4 instead of 4.0). The "-moisture" is not proper C
and should be written "-1.0*moisture". I remember programs behaving
strangely when I forgot to make this adjustment. These two factors taken
together could very probably account for the large values returned by
the print statements for threshold, although it is harder to explain the
overrun for randNum. However it could be a strange byproduct of the
variable threshold going to infinity.
I've copied some of Paul's code and output below so you can figure out
what I'm talking about:
- makeDecisionAtUrgency: (float) urgency {
double randNum;
double threshold;
threshold = urgency * load * exp(-moisture / 4);
randNum = [uniformDblRand getDoubleWithMin: 0.0 withMax: 1.0];
if (randNum < threshold)
[self setBurning: 1];
else
[self setBurning: 0];
printf ("\t\t fuel compared %f and %f \n", randNum, threshold);
return self;
}
The printf statement was added as a way to check why things were going
wrong when this ran on my laptop. At this part of the simulation, the
printf statement gave the following output:
fuel compared 0.353868 and -27255296557.392986
fuel compared 0.313851 and 9945314261.998653
fuel compared 0.007383 and 18195143603.152775
fuel compared 0.236007 and -12823928380.525589
fuel compared 0.304299 and 4679383970.345970
fuel compared 0.628275 and 8561022917.100419
fuel compared NaN and -28163390113.579769
fuel compared NaN and 10276672821.115992
fuel compared NaN and 18801370456.165474
fuel compared NaN and -8273947266.455919
fuel compared NaN and 3019119809.569216
fuel compared NaN and 5523537722.697916
Regards,
Benedikt
--
---
Present coordinates:
Dep. of Economics, Univ. of Trento, Via Inama 1, 38100 Trento, ITALY
Office: +39 0461 882246 Mobile: +39 0347 0415721 Fax: +39 0461 882222
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
- wierd random number behavior, Paul Box, 1999/04/19
- Re: wierd random number behavior, Sven N. Thommesen, 1999/04/19
- Re: wierd random number behavior, Paul Box, 1999/04/19
- Re: wierd random number behavior, Theodore C. Belding, 1999/04/20
- ANYBODY USING AMD PROCESSORS ?, Sven N. Thommesen, 1999/04/20
- Re: wierd random number behavior, Sven N. Thommesen, 1999/04/20
- Re: wierd random number behavior,
Benedikt Stefansson <=
- Re: wierd random number behavior, Marcus G. Daniels, 1999/04/20
- Re: wierd random number behavior, Benedikt Stefansson, 1999/04/20
- Re: wierd random number behavior, Tamas Papp, 1999/04/20
- Re: wierd random number behavior, Marcus G. Daniels, 1999/04/20
- Re: wierd random number behavior, Paul Box, 1999/04/21
- Re: wierd random number behavior, Theodore C. Belding, 1999/04/21
Re: wierd random number behavior, Marcus G. Daniels, 1999/04/19