Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么Math.Atan2(-0.0,x)返回与Math.Atan2(0.0,x)不同的结果?_C#_.net_Math - Fatal编程技术网

C# 为什么Math.Atan2(-0.0,x)返回与Math.Atan2(0.0,x)不同的结果?

C# 为什么Math.Atan2(-0.0,x)返回与Math.Atan2(0.0,x)不同的结果?,c#,.net,math,C#,.net,Math,请注意(使用LinqPad): 即声明 (0.0 == -0.0).Dump(); Math.Atan2(-0.0, -0.3).Dump(); Math.Atan2(0.0, -0.3).Dump(); 评估 True -3.141592653589793 3.141592653589793 Powershell中也是如此: C:\Users\ethan>[数学]::Atan2(-0.0,-0.3) -3.14159265358979 C:\Users\ethan>[math]::Ata

请注意(使用LinqPad):

即声明

(0.0 == -0.0).Dump();
Math.Atan2(-0.0, -0.3).Dump();
Math.Atan2(0.0, -0.3).Dump();
评估

True
-3.141592653589793
3.141592653589793
Powershell中也是如此:

C:\Users\ethan>[数学]::Atan2(-0.0,-0.3)
-3.14159265358979
C:\Users\ethan>[math]::Atan2(0.0,-0.3)
3.14159265358979
C:\Users\ethan>0.0-eq-0.0
符合事实的
C:\Users\ethan>
世界跆拳道联合会?

如第45页中的定义:

对于具有正符号位的y,atan2(y,x)的特例 涉及0和∞ 表示不精确异常的常数 但没有其他例外:

  • atan2(±0,−0)为±π
  • atan2(±0,+0)为±0
  • atan2(±0,x)对于x0为±π
  • atan2(y,±0)为−y0的π/2
  • atan2(±y,−∞) 有限y>0时为±π
  • atan2(±y+∞) 有限y>0时为±0
  • atan2(±∞, x) 对于有限x为±π/2
  • atan2(±∞, −∞) 为±3π/4
  • atan2(±∞, +∞) 为±π/4

这有什么不同呢?你知道角度方向therms上的
-PI=+PI
,如果你在
范围内得到这两个结果,那么,-PI不等于PI。这是在这个上下文中,但是你怎么知道-0.0是否给定?毕竟0.0=-0.0?@Ethakharitonov 0.0和-0.0是IEEE754下的两个不同的数字。大多数操作,比如平等对待它们是一样的,但有时,它们被不同地对待,正如第3页所讨论的。只是好奇,如果平等说它们是一样的,我的代码如何区分这两者。我的意思是我不能只检查它是否小于0,对吗?@Ethakharitonov
double.IsNegative
会告诉你它是否为负。