As we know, there is float number precision problem when comparing float numbers.
Also that NSSet uses equality compare to keep elements unique in it.
So what happens when NSSet stocks NSValues that have float/double in it,
Should we never use float in NSSet to avoid float precision problem?
there is float number precision problem when comparing float numbers.
To be precise, only comparison for equality presents a problem. Unfortunately, that's the kind of comparison done by NSSet
.
So what happens when
NSSet
stocksNSValues
that havefloat
/double
in it?
It treats numbers that are really close to each other but not exactly equal as different items in the set. That is why one should be extremely careful when using floating point numbers in NSSet
. Ideally, you should avoid it if you can.