views:

123

answers:

3

When I create a test using MS Visual Studio's builtin unit test wizard it creates code with lines like the below:

double number = 0F;

In C# "F" stands for float, case-independent, and "D" for double. Using "F" suffix instead of "D" leads to precision lost.

If it's a bug, where can I report it to Microsoft?

+2  A: 

I don't see how that could be anything but a bug. Completely harmless in this case, but still a bug. You can use Connect to report this kind of thing. However, I've had much more important bugs swept aside than this so I wouldn't expect much action.

HTH, Kent

Kent Boogaart
Oh thanks. I submitted the bug https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=417343
Jader Dias
A: 

If you use a Decimal (M suffix) then you don't have to worry about it having estimation errors or precision loss.

DevelopingChris
-1: Yes, instead you get "Cannot implicitly convert type 'decimal' to 'double'. An explicit conversion exists (are you missing a cast?)"
R. Bemrose
and your calculations, will never be precise enough to actually test
DevelopingChris
A: 

If the value is always 0F then no information will be lost at all.

In general any float can be converted to a double with no loss of precision (IEEE 754 assumed).

So long as the test value has not needed truncation to be represented as a float then there is no problem with regards to correctness. The confusion to end users and increased hassle when wanting to modify the values is still a problem.

ShuggyCoUk
But it induces the developer to believe that F is for doubles. And it makes a little harder to write a double constant because the developer would have to replace 2 chars instead of one.
Jader Dias
I agree that it is poor (sorry if I gave the impression it was a *good* thing) just pointing out that the precision issue isn't a problem except where the literal value had to be truncated to fit in the float.
ShuggyCoUk