Closed t-b closed 1 year ago
This is a really really weird edge case. With CHECK_EQUAL_VAR(0, str2num("-0"))
I get no error. After fiddling a bit in C# I got an interesting result:
public static void Main()
{
double v1 = 0.0;
double v2 = double.Parse("-0.0");
// numeric comparison
Console.WriteLine($"{v1}={v2}: {v1 == v2}");
// binary comparison
Console.WriteLine($"{Conv(v1):x16}={Conv(v2):x16}: {Conv(v1) == Conv(v2)}");
}
public static ulong Conv(double value)
=> BitConverter.DoubleToUInt64Bits(value);
// Output:
// 0=-0: True
// 0000000000000000=8000000000000000: False
So I think the problem here is that CHECK_EQUAL_WAVES
compares the whole wave with binary comparison which points out the difference between "0" and "-0" and then use numeric comparison to find the different field. To fix this is really difficult because we have to use binary comparison for each field again to find the difference. An alternative way would be to compare the whole wave with numeric comparison in the first place and don't do the binary comparison.
We can also do binary comparison in the first place. Then search for the difference with numeric comparison and if we didn't find something we assume that the waves are indeed the same and change the assertion status back to succeeded. This can also enable case-insensitive comparison for text waves.
We will not be fixing this for now. This is too much of an edge case.
gives
I'm mostly posting this here for educational purposes. I don't think we really need to fix the diff. One would also need to lookup if
-0 == 0
with IEEE754.