![](/img/trans.png)
[英]Can object.GetHashCode() produce different results for the same objects (strings) on different machines?
[英]BigFloat calculations produce different results in various machines
我在我的項目中使用第三方庫來獲取 BigFloat 值(我使用了這兩個庫https://github.com/Osinko/BigFloat和https://www.nuget.org/packages/BigFloat )。 我在我的機器上得到的結果是想要的結果; 然而,當我在其他機器上運行應用程序時(我在 3 台不同的機器上測試)應用程序給出了不同的結果(所有三台機器都給出了相同的數字,這與我在我的機器上得到的值不同並且不是可接受的值我的應用程序)。 我研究了各種關於浮點計算在不同機器上的不同結果的帖子,但是在所有三台機器上產生的結果都是一樣的。 所以,我想知道我是否遺漏了什么。 或者,我該如何解決這個問題?
function 中執行計算的部分是(thisItemCount、count_system、userDuration、repairTime、MTBFValue 和 workingRate 值是我從用戶通過表單輸入的值的兩倍):
// Calculate the effective total failure rate
double FailureRate = (thisItemCount * Count_system * useDuration * repairTime) /
(MTBFvalue / workingRate);
//FailureRate = Math.Round(FailureRate, 8, MidpointRounding.AwayFromZero);
// Calculate the required number of spares
int n = 0;
BigFloat failureProbability = 0;
BigFloat adequacy = 0;
for (int j = 0; j < 150; j++)
{
try
{
BigFloat power = BigFloat.Pow(FailureRate, n);
failureProbability = power / Factorial(n);
adequacy += failureProbability;
BigFloat Exp = (BigFloat)(Math.Exp(-FailureRate));
BigFloat FA = Exp * adequacy;
double Level = _spareAvailability / 100;
BigFloat AvailabilityLevel = new BigFloat(Level);
if (FA >= AvailabilityLevel)
{
Console.WriteLine("Break");
break;
}
n++;
}
catch (Exception ex)
{
Console.WriteLine("Didn't calculate this row");
Console.WriteLine(ex);
}
}
result.Text = n.ToString();
這可能是這台機器的文化。
在您的源代碼中明確文化,然后重試。
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); // your culture
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.