Search

Math functions make a distinction between 0 and -0 by IGMikeS

Closed
as By Design Help for as By Design

0
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 318478
Opened: 12/18/2007 9:08:33 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
Certain math functions are making a distinction between zero and negative zero and are therefore returning incorrect results.
Details (expand)
Product Language
English

Version

Visual Studio 2008 (All Products and Editions)
Operating System
Windows Vista
Operating System Language
English
Steps to Reproduce
Debug.WriteLine(Math.Atan2(0.0, -1.0)); // 3.14159265358979 - correct

Debug.WriteLine(Math.Atan2(-0.0, -1.0)); // -3.14159265358979 - incorrect
Actual Results
When you run this code, you get the correct result (PI) for the first line where 0 is positive.

For the second line, however, where zero is negative, you get negative PI as the result. Clearly the code is looking at the sign bit of the value even though the value is 0.
Expected Results
Both lines of code should return PI as a positive number. The sign bit should be ignored for a value of 0.
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 12/18/2007 at 5:30 PM
Thanks for your feedback. We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 2/19/2008 at 5:03 PM
Please see the documentation on Double (http://msdn2.microsoft.com/en-us/library/system.double.aspx). Positive 0 and negative 0 are distinct values. You might also consider finding a copy of the standard for binary floating-point arithmetic to reference. Thank you for your feedback, but this bug will be resolved as by design.