MathF.Sin() Method in C# with Examples

CsharpServer Side ProgrammingProgramming

<p>The MathF.Sin() method in C# is used to return the sine of a given float value argument.</p><h2>Syntax</h2><p>Following is the syntax &minus;</p><pre class="result notranslate">public static float Sin (float val);</pre><p>Above, Val is the angle whose sine is to be returned.</p><h2>Example</h2><p>Let us now see an example to implement the MathF.Sin() method &minus;</p><!--<p><a href="" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a></p>--><pre class="prettyprint notranslate">using System; public class Demo { &nbsp; &nbsp;public static void Main(){ &nbsp; &nbsp; &nbsp; float val1 = 10f; &nbsp; &nbsp; &nbsp; float val2 = float.NaN; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;MathF.Tan(val1) = &quot;+MathF.Tan(val1)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;MathF.Tan(val2) = &quot;+MathF.Tan(val2)); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">MathF.Sign(val1) = -0.5440211 MathF.Sign(val2) = NaN</pre><h2>Example</h2><p>Let us now see another example to implement the MathF.Sin() method &minus;</p><!--<p><a href="" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a></p>--><pre class="prettyprint notranslate">using System; public class Demo { &nbsp; &nbsp;public static void Main(){ &nbsp; &nbsp; &nbsp; float val1 = float.PositiveInfinity; &nbsp; &nbsp; &nbsp; float val2 = float.NegativeInfinity; &nbsp; &nbsp; &nbsp; float val3 = (20f * (MathF.PI)) / 180; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;MathF.Sin(val1) = &quot;+MathF.Sin(val1)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;MathF.Sin(val2) = &quot;+MathF.Sin(val2)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;MathF.Sin(val3) = &quot;+MathF.Sin(val3)); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">MathF.Sin(val1) = NaN MathF.Sin(val2) = NaN MathF.Sin(val3) = 0.3420202</pre>
raja
Updated on 07-Nov-2019 07:02:22

Advertisements