[MBDyn-users] Bug in mathematical parser (fixed)

Pierangelo Masarati masarati at aero.polimi.it
Thu May 1 18:19:07 CEST 2008

Alessandro Fumagalli reported a bug in the mathematical parser, which is 
used to parse numbers and mathematical expressions in input files as 
well as "string" drives.  The bug consists in an erroneous casting of 
values when assigning them to variables.  To make the story short, 
variables would lose their definition in favor of the type of the value 
they were assigned, so:

	set: real X = 1;

would turn X into an integer, since "1" is read as an integer.  This 
would be harmless in most of the cases, since using "X" where a real is 
required would have resulted in using the correct value anyway.

The effect of the bug is quite subtle, since it would mainly manifest 
itself when using the variable in expressions.  So, continuing with the 
above example,

	set: real Y = X/2;

would have resulted in assigning "0" to "Y", since "X" and "2" are 
integers, and the division is now performed between integers, correctly 
resulting in "1/2 = 0".

The bug causes no harm if all real values are explicitly written as 
reals, namely including a ".".  The parser has been fixed with respect 
to this issue, and strengthened with respect to casting.  Now it warns 
when a casting that alters the value is performed.  The warning needs to 
be improved since it does not indicate where and why it happens.

The bug was introduced in the 1.3 branch.  The fix will be in the next 
(1.3.4) release.

Cheers, p.

More information about the Mbdyn-users mailing list