在C#Math.Atan2或类实例的问题 [英] Math.Atan2 or class instance problem in C#
问题描述
下面是我的问题(C#):
Here is my problem (C#) :
double Y = 0.0;
double X = -21.0;
double q1_Test = Math.Atan2(0.0, -21.0); // gives Math.Pi
double q1_Test2 = Math.Atan2(( double)Y, (double)X); // gives Math.Pi
double w1 = <SomeclassInstanceGlobalHere>.getW1(); // This is a class which updates a variable
double w2 = <SomeclassInstanceGlobalHere>.getW2(); // This is a class which updates a variable
double q1 = Math.Atan2(w2, w1); // ** gives -Math.Pi ** ???
//w2 shows 0.0 and w1 shows -21.0
当我从其他类中的值,变量值分别为0.0和-21.0。它也显示在IDE中调试时。 这是怎么回事错在这里?
When I get the values from the other class, variable values are 0.0 and -21.0 respectively. It also shows in the IDE while debugging. What is going wrong here?
推荐答案
W2必须真正-0.0,其格式为0
w2 must actually be -0.0, which is formatted as 0
下面的博客文章显示您如何实际测试这种(Decimal.GetBits(值)): <一href="http://blogs.msdn.com/bclteam/archive/2006/10/12/decimal-negative-zero-re$p$psentation-lakshan-fernando.aspx" rel="nofollow">http://blogs.msdn.com/bclteam/archive/2006/10/12/decimal-negative-zero-re$p$psentation-lakshan-fernando.aspx
The following blog post shows how you can actually test for this (Decimal.GetBits(value)): http://blogs.msdn.com/bclteam/archive/2006/10/12/decimal-negative-zero-representation-lakshan-fernando.aspx
这篇关于在C#Math.Atan2或类实例的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!