@(0.3)
uses -numberWithDouble:
because 0.3
has type double
. If you wrote @(0.3f)
then it would use -numberWithFloat:
.
Neither float
nor double
can store 0.3 exactly. (It's similar to the problem of writing 1/3 in decimal form - you can't do it exactly using a finite number of digits.) Instead, you get the float
closest to 0.3 and the double
closest to 0.3. These two numbers are not equal to each other, so -containsObject:
can't find a match.
Both float
and double
can store 0.0 and 1.0 exactly, so both conversions give you the same result and -containsObject:
succeeds.