From: Hugo C. <hug...@gm...> - 2015-07-22 22:15:09
|
Hi Cengiz, I quickly checked the behaviour of both commands with GDB, and here is what happens: The first result 0.5500000385 is correct, GDB reports 0.55000003851059043 as the double precisions result. For the behaviour of the second command: echo { 2012303744.1 / 3658733824 } What happens goes as follows: The second argument in the input, the integer 3658733824, is larger than the highest signed 32bit integer (which is 2147483647). GENESIS uses the sscanf() function to read the integer from the command line. This function does not generate an error when an overflow occurs and simply returns 2147483647, so GENESIS continues its operation with this result assuming everything is fine. So internally the command is treated as this command: echo { 2012303744.1 / 2147483647 } for which GDB returns: 0.93705195236813832 Obviously, this behaviour is totally undesired and GENESIS should emit an error message for the integer overflow, but does not. The work around is as you say, to suffix a .0 after the integer to force GENESIS to use floating point calculations. Hugo On Wed, Jul 22, 2015 at 10:48 PM, Cengiz Günay <cg...@em...> wrote: > Hi, > > I have been pulling my hair trying to debug arithmetic inconsistencies in > Genesis that are caused by large truncation errors from simplest > calculations and inconsistent PI definitions, which I realize have been > known and we need to be cautious about. However, I wanted to report > something really disturbing: > > > echo { 2012303744.1 / 3658733824.0 } > 0.5500000385 > > echo { 2012303744.1 / 3658733824 } > 0.9370519524 > > Does anyone have an explanation for this behavior? This can cause > seriously wrong calculations and hidden bugs. > > I think the take home message is to always put a .0 behind integer numbers > that are going to be in floating point calculations. :) > > Best, > -Cengiz > > -- > Cengiz Gunay > Postdoctoral Fellow, Dept. of Biology > Visiting Faculty, Dept. of Math & CS > Emory University > http://www.biology.emory.edu/research/Prinz/Cengiz/ > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Genesis-sim-users mailing list > Gen...@li... > https://lists.sourceforge.net/lists/listinfo/genesis-sim-users > > -- Hugo -- Hugo Cornelis, Ph.D. Agora Classica -- CTO http://www.agoraclassica.com/ <http://www.genesis-sim.org/> GENESIS-3 -- lead architect http://www.genesis-sim.org/ |