MathF.Tan() Method in C# with Examples

CsharpServer Side ProgrammingProgramming

<p>The MathF.Tan() method in C# is used to return the tangent of a given float value argument.</p><h2>Syntax</h2><p>Following is the syntax &minus;</p><pre class="result notranslate">public static float Tan (float val);</pre><p>Above, Val is the angle whose tangent is to be returned.</p><h2>Example</h2><p>Let us now see an example to implement the MathF.Tan() 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.Tan(val1) = 0.6483608 MathF.Tan(val2) = NaN</pre><h2>Example</h2><p>Let us now see another example to implement the MathF.Tan() 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.Tan(val1) = &quot;+MathF.Tan(val1)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;MathF.Tan(val2) = &quot;+MathF.Tan(val2)); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;MathF.Tan(val3) = &quot;+MathF.Tan(val3)); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">MathF.Tan(val1) = NaN MathF.Tan(val2) = NaN MathF.Tan(val3) = 0.3639702</pre>
raja
Updated on 05-Nov-2019 07:42:02

Advertisements