How would you explain the following code never getting into the
if clause? Bear in mind I already knew it to be true at least once. I was an absolute true.
1 2 3 4 5 6 7 8 9 10
Printing the value also proved to be pointless:
1 2 3 4 5
Finally, XCode’s debugger shed a dim of light to the real issue. It showed that the true value of
subviewAlpha is 0.14999999999999999, and as a floating point it’s accurate. Meanwhile the value of
myAlpha was 0.15000000596046448, so logically they are different. But what could be causing this singularity?
CGFloat definition, we can see that it may be an alias to float or double, depending on the system’s architecture (x32 or x64). As I neglected to search, Apple had it documented and it could have saved me some time (thanks @gustavocsb, for the link).
As usual, I solved it the more elegant way I could. “Hey, if
CGFloat is bipolar, let it tell me how to read it!”
1 2 3 4 5 6 7 8
Conclusion, always have in mind that typings and comparisons may not be as obvious as they seem. Be careful and, when in doubt,