0

I am using a third-party library in my project for BigFloat values (I used these two libraries https://github.com/Osinko/BigFloat and https://www.nuget.org/packages/BigFloat). The results I get in my machine is the wanted results; however, when I run the application in other machines (I test in 3 different machines) the application gave a different result (all three gave the same number which is different from the value I got in my machine and isn't an acceptable value for my application). I study various posts regarding different results in different machines regarding floating-point calculation, but the result produces in all the three machines were the same. So, I wonder if I am missing something. Or, how can I solve this problem?

The part of the function that does the calculation is (thisItemCount, count_system, userDuration, repairTime, MTBFValue, and workingRate values are double which I get from the user's entry via form):

// 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();
Omkar76
  • 1,317
  • 1
  • 8
  • 22
Sanam
  • 77
  • 1
  • 11
  • Is "different" like "slightly different, may be a precision/rounding issue" or "completely different" – Klaus Gütter Sep 20 '20 at 17:03
  • @KlausGütter actually really different. Sometimes it is near to double the value it should be and sometimes it is 0 where it should be for example 75. – Sanam Sep 21 '20 at 07:08

1 Answers1

1

It's maybe could be the culture of this machines.

Explicit the culture in your source code and try again.

CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); // your culture
  • Using this line in my code caused the application to gave wrong results in my machine too. But again different from the results shown in other machines. But I try to play with it a little to see if I can solve the problem using culture. Thanx – Sanam Sep 21 '20 at 07:52