C#中的Math.Atan2或类实例问题 [英] Math.Atan2 or class instance problem in C#

查看:285
本文介绍了C#中的Math.Atan2或类实例问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题(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(value)):
http://blogs.msdn.com/bclteam/archive/2006/10 /12/decimal-negative-zero-representation-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆