Sunday, 1 June 2008

Ceteris Paribus

Wikipedia tells me that:
Cēterīs paribus is a Latin phrase, literally translated as "with other things the same". It is commonly rendered in English as "all other things being equal".

Following on from yesterday's post, True and False, I felt that this seemed like a good title for something with a similar theme.

This is another bug we found in the same third-party supplier's components, and another quick sample we knocked up to illustrate the problem.
Private Sub Form_Load()

With TestControl2
   .Format = "#0.00"
   .DisplayFormat = "#0.00"
   .MaxValue = 99.99
   .Value = 99.99
   Debug.Print "Value:         " & .Value
   Debug.Print "Max:           " & .MaxValue
   Debug.Print "Value > Max:   " & (.Value > .MaxValue)
   Debug.Print "Value > 99.99: " & (.Value > 99.99)
   Debug.Print "99.99 > Max:   " & (99.99 > .MaxValue)
   Debug.Print "99.99 > 99.99: " & (99.99 > 99.99)
End With

End Sub

So, we're talking about a similar set of circumstances - we're sticking a value (99.99) and then viewing and comparing it to, well, 99.99.

One would traditionally expect, all other things being equal ;), for 99.99 to be the same as 99.99. Let's check that, shall we?

Value:         99.99
Max:           99.99
Value > Max:   True
Value > 99.99: True
99.99 > Max:   False
99.99 > 99.99: False

Ah, of course. Value is greater than MaxValue. In other words, 99.99 is greater than 99.99. Good. Right. Erm... ;)

What seems to have happened here is that, for some reason (don't ask me what), the "99.99" that we put into "Value" seems to have been artificially increased, for example, to 99.991, but when we display it it is rounded back down to 99.99.

Both this problem, and the one documented by True and False, are both perfect examples of things going wrong that just should not go wrong. Discovering that 99.99 is a larger number than 99.99 just should not happen. But it does. And when it does, you can guarantee that it'll only expose itself under some bizarre set of circumstances that don't make any sense.
After hours of following through code and feeling thoroughly confused, you eventually arrive at that place where you begin to examine the things that it wouldn't usually occur to check.

And that's when you find the little bugger that's been ruining your day. Hurrah!

No comments:

Post a comment