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

Stephan Rudlof squeak-dev at lists.squeakfoundation.org
Fri Oct 25 13:29:35 UTC 2002


tim at io.com wrote:
> 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.

I understand: I had have to know that using #basicAt: is dangerous, but in
spite of this the compiler could avoid this problem here (by 'seeing' that
there is a change of the literal, but I fear that a general solution would
be to avoid sharing literals). One lame excuse for overlooking this: I think
I'm too used to think in SmallInteger arithmetics terms...

Greetings,

Stephan

> 
> 	-- tim
> 
> 


-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3




More information about the Squeak-dev mailing list