I understand floating point numbers can be somewhat imprecise but I'm a bit bothered today when I see the following evaluates to false:
1: float f = .16f;
2: double d = .16d;
4: Assert.That(f, Is.EqualTo(d))
Annoyingly I wanted to see what the two values are:
produces the following respectively:
What bothers me about this, and I'm hoping someone can eloquently explain this, the MSDN docs say this should be implicitly converted. From the MSDN doc article on implicit numeric conversions:
Float is 32-bit and double is 64-bit, so why can't the float fit nicely inside the address space for the double?
Hell, if you're not going to respect the integrity of the number what's the point of the implicit conversion?
11-05-2008 2:13 PM