2014-07-12 17:00 GMT+02:00 Nicolas Cellier < nicolas.cellier.aka.nice@gmail.com>:
2014-07-12 13:42 GMT+02:00 Andres Valloud < avalloud@smalltalk.comcastbiz.net>:
Being consistent then means either abandonning 1/2 = 0.5 but we saw this
has nasty side effects.
Well ok, so letting 1 / 2 = 0.5 answer false has nasty side effects. Why is that? Isn't the code that breaks trying to tell us something? That's what I've been trying to point out. Why rush to defend numerically unstable code? What are we going to preserve, and what will be the example given to others?
Andres.
What apparently breaks Pharo graphics is letting (1 comparisonOp: 1.0) = false in Float>>adaptToInteger:andCompare: (maybe my mistake, I should ^ operator = #~= rather than ^false) At this point, we can't tell that the code is numerically unstable. Maybe the Float are very well formed and sufficiently away from int, or exactly equal to int... Only if we see off-by-one errors can we conclude that there are design mistakes. Or if we perform a deeper analysis, but it ain't going to be easy. To know where it happens, we would have to instrument code (no static typing).
It's not un-interesting. But it's going to waste a lot of time for a problem we don't yet have...
So I gave a try to instrumentation with one of my dirtiest hack: 1) define a new Notification subclass: #IntegerFloatComparison 2) raise this signal in Float>>adaptToInteger:andCompare: IntegerFloatComparison signal ...snip... 3) catch the senders using the message tally: tally := MessageTally new. tally spyEvery: 100 on: ['em ezilaitini ot si siht' reverse]. tally class: World class method: World class>>#doOneCycle. tallyEnd := false. [(Delay forSeconds: 300) wait. tallyEnd := true] fork. [[World doOneCycle. Processor yield.tallyEnd] whileFalse] on: IntegerFloatComparison do: [:exc | tally tally: exc signalerContext by: 1. exc resume]. (StringHolder new contents: (String streamContents: [:s | tally report: s])) openLabel: 'EndOfStream Spy Results'. 4) do your favourite activity... After 5 minutes of typical browsing/workspace activity, > 100 000 sends in Morph, TableLayout, bounds etc... But are the Float possibly ill-formed? I modified the signaller: (self fractionPart = 0) ifFalse: [IntegerFloatComparison signal]. Hmm 0 tallies this time. So I don't know where exactly Float are required (some primitive do not accept Fraction I think this is the main reason why some asFloat have been spreaded...). But these are innocuous Float. No numerical unstable code detected by this cheap exercize.