How dangerous is it to compare floating point values?

I know UIKit uses CGFloat because of the resolution independent coordinate system. But every time I want to check if for example frame.origin.x is 0 it makes me feel sick: if (theView.frame.origin.x == 0) { // do important operation } Isn’t CGFloat vulnerable to false positives when comparing with ==, <=, >=, <, >? It … Read more

What is the best way to compare floats for almost-equality in Python?

It’s well known that comparing floats for equality is a little fiddly due to rounding and precision issues. For example: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ What is the recommended way to deal with this in Python? Surely there is a standard library function for this somewhere? 17 Answers 17

What is the difference between float and double?

I’ve read about the difference between double precision and single precision. However, in most cases, float and double seem to be interchangeable, i.e. using one or the other does not seem to affect the results. Is this really the case? When are floats and doubles interchangeable? What are the differences between them? 14 s 14 … Read more