`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

asked March 23rd 20 at 18:48

1 answer

answered on

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.**

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.

Find more questions by tags C#

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