Why are the console outputs NaN?

double y = Math.Pow(Math.Log(0.2 + Math.Sin(x)), 2);

If you enter some numbers such as 4.5 displays Nan tried everything and was -1 Donegal and the module took it all-just NaN
March 23rd 20 at 18:48
1 answer
March 23rd 20 at 18:50
Solution
The sine can be negative. I think the error occurs when you take a sine from PI to zero. Pochakaite.

Okay, pracical himself - Yes, sine 4,5 negative and greater than 0.2. The addition gives a negative number and that's where the Shoe pinches.

PS let me explain for posterity is to try to calculate base 2 logarithm from a negative number returns NaN.
All thanks understood - Uriel.Cormier commented on March 23rd 20 at 18:53
@Uriel.Cormier, that is, to verify that the sinus was negative.
You can calculate 0.2 + Math.Sin(x) before performing the calculation of the logarithm and if it is negative, not to perform the calculation. - Cathrine15 commented on March 23rd 20 at 18:56
@Cathrine15, Yes, thank you did - Uriel.Cormier commented on March 23rd 20 at 18:59

Find more questions by tags C#