[BUG][3.2][Linux] Float arithmetic: Squeak<->C Float conversion problem?

tim at io.com tim at io.com
Fri Oct 25 01:21:39 UTC 2002


Stephan Rudlof <sr at evolgo.de> wrote:
| "Bug"
| "Wrong:"
| | onePlusEpsilon epsilon |
| onePlusEpsilon _ 1.0 basicAt: 2 put: 1; yourself.
| epsilon _ onePlusEpsilon - 1.0.
| epsilon = 0.0 -> true
| 
| "OK:"
| | onePlusEpsilon |
| onePlusEpsilon _ 1.0 basicAt: 2 put: 1; yourself.
| onePlusEpsilon inspect
| "and in the inspector"
| self - 1.0 = 0.0 -> false
| 
| Very weired...
| 
| Squeak<->C Float conversion problem?

No, it turns out to be the standard strange problem you get when you
modify a literal (in this case, the literal 1.0) which is used multiple
times in the method.  The compiler combines multiple references to the
same literal to point to a single copy of that literal.  So when you
modify it in place in the first line, the second reference to "1.0" in
the second line is pointing to the modified value, epsilon will always
be zero.

It works in the inspector, because the compiled code fragment in the
inspector uses a different literal 1.0, which really is 1.0.

	-- tim



More information about the Squeak-dev mailing list