Can someone please confirm, and explain, why this happens:
On simulator (7.1, 32-bit):
NSNumber *a = [NSNumber numberWithFloat:0.5]; // hash = 506952114
NSNumber *b = [NSNumber numberWithFloat:1.0]; // hash = 2654435761
NSNumber *c = [NSNumber numberWithFloat:2.0]; // hash = 1013904226
On device (7.1, 32-bit):
NSNumber *a = [NSNumber numberWithFloat:0.5]; // hash = 2654435761
NSNumber *b = [NSNumber numberWithFloat:1.0]; // hash = 2654435761 - SAME!
NSNumber *c = [NSNumber numberWithFloat:2.0]; // hash = 5308871522
I thought it might be a 32-bit issue, but when I try the same thing on 64-bit simulator and device, I get the SAME issue. Simulator is fine, device has identical hashes.
I was trying to add unique objects to an NSMutableOrderedSet
and noticed that my two objects that were identical except for differing values of 0.5 and 1.0 were not both being added, and this is why. I tried both floats and doubles with the same result.
But why?