Here is the example with comments:
class Program
{
// first version of structure
public struct D1
{
public double d;
public int f
Simpler test case:
Console.WriteLine("Good: " + new Good().Equals(new Good { d = -.0 }));
Console.WriteLine("Bad: " + new Bad().Equals(new Bad { d = -.0 }));
public struct Good {
public double d;
public int f;
}
public struct Bad {
public double d;
}
EDIT: The bug also happens with floats, but only happens if the fields in the struct add up to a multiple of 8 bytes.