osman Rahimi
osman Rahimi

Reputation: 1497

Math.Sinh() return different value in c#

I have this Code in my program :

Math.Sinh(myvalue).ToString()

Above Code returns Infinity in windows 8 and return in windows 10 .

why it return two diffrent values ?

Upvotes: 2

Views: 97

Answers (1)

René Vogt
René Vogt

Reputation: 43876

The return value of Math.Sinh(myvalue) is still the same double.PositiveInfinity. I assume that the resource files containing the string representation for the special double values have been changed in Windows 10 so they now return that infinity symbol .

If you want to keep your code the old way (which in fact is not a good idea to depend on culture-specific string representations), you may consider something like this:

double sinh = Math.Sinh(myvalue);
string v = double.IsInfinity(myvalue) ? "Infinity" : myvalue.ToString();

or simply check if the return value of ToString() is and change it accordingly.

But remember that there are some more special double values you may have to check.

Upvotes: 4

Related Questions