[Gambas-user] Issue 121 in gambas: The example Evaluator returns strange results when working with integer/long numbers
gambas at ...2524...
gambas at ...2524...
Mon Oct 3 20:53:04 CEST 2011
Status: New
Owner: ----
Labels: Version Type-Bug Priority-Medium OpSys-Any Dist-Any Arch-Any
Desktop-Any GUI-Any
New issue 121 by stephane... at ...626...: The example Evaluator returns
strange results when working with integer/long numbers
http://code.google.com/p/gambas/issues/detail?id=121
1) Describe the problem.
If the formula that you enter in the evaluator contains only contains whole
numbers (no decimals) and no function, the calculation is made using
integer math which may look odd to an inexperienced user.
2) GIVE THE FOLLOWING INFORMATIONS (if they are appropriate):
Version: TRUNK 2.99.4
Revision: r4168
3) Provide a little project that reproduces the bug or the crash.
See #5
4) If your project needs a database, try to provide it, or part of it.
n/a
5) Explain clearly how to reproduce the bug or the crash.
Open the example Evaluator (File > Open example > Miscellaneous >
Evaluator) and run it. In the textbox corresponding to "a=", enter 29999.
In the formula, enter a*a*a. Click the button "Update result". You get a
negative number which is obviously wrong. The reason is that the evaluation
component works with long numbers and does math modulo 2^32.
To fix the bug, I suggest to change:
Click on
http://gambas.svn.sourceforge.net/viewvc/gambas/gambas/trunk/examples/examples/Misc/Evaluator/.src/FEval.class?revision=2078&view=markup
Change the lines 26-29 into:
$cEnv["a"] = CFloat(Val(txtValueA.Text))
$cEnv["b"] = CFloat(Val(txtValueB.Text))
$cEnv["x"] = CFloat(Val(txtValueX.Text))
$cEnv["y"] = CFloat(Val(txtValueY.Text))
to force a calculation using floating point numbers.
6) By doing that carefully, you have done 50% of the bug fix job!
More information about the User
mailing list