[英]Math.Cos(x)<-1 with large values of x
我寫了非常簡單的代碼:
public static void Main (string[] args)
{
String str="1,0992748756871115E+41"; //yes, I know that is very large value
Double x=Convert.ToDouble(str);
Double res=Math.Cos(x);
Double resRound=Math.Round(res);
Console.WriteLine("x={0}\nres={1}\nresRound={2}", x, res, resRound);
}
並且此代碼輸出非常大的res值: 1,09927487568711E+41
其中a等於Math.Cos的參數:
我想,這是Gtk#
一個錯誤,並決定測試返回.NET Framework編譯的代碼的值,它返回相同的值! 這是因為函數cos(x)的含義超過了從-1
到1
的段的限制嗎? 怎么可能?
從文檔 :
可接受的d值范圍從大約-9223372036854775295到大約9223372036854775295.對於此范圍之外的值,Cos方法返回d而不是拋出異常。
您可以細分表達式以獲取值
成本(A + B)= CosA * CosB -SinA * SinB
在文檔限制范圍內盡可能低地分解
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.