Is it possible for the GetHashCode()
method to return different integer values for the same double
value on different computers, operating systems, or architectures? For example, if I have the following code:
public unsafe override int GetHashCode() {
double d = m_value;
if (d == 0) {
// Ensure that 0 and -0 have the same hash code
return 0;
}
long value = *(long*)(&d);
return unchecked((int)value) ^ ((int)(value >> 32));
}
Could hash1
be a different integer on a different computer or operating system than it is on the original computer? Is the behavior of GetHashCode()
for double
values consistent across different environments?