Ruby - Math.tan() Method
The Ruby Math.tan() method returns trigonometric tangent of an angle (angle should be in radians). The return type of this method is float.
In the graph below, tan(x) vs x is plotted.
Syntax
Math.tan(x)
Parameters
x |
Specify the angle in radian. |
Return Value
Returns the trigonometric tangent of an angle.
Example:
In the example below, Math.tan() method is used to find out the trigonometric tangent of an angle.
#Math::PI - value of PI from Math module pi = Math::PI puts "Math.tan(pi/6) = #{Math.tan(pi/6)}" puts "Math.tan(pi/4) = #{Math.tan(pi/4)}" puts "Math.tan(pi/3) = #{Math.tan(pi/3)}"
The output of the above code will be:
Math.tan(pi/6) = 0.5773502691896257 Math.tan(pi/4) = 0.9999999999999999 Math.tan(pi/3) = 1.7320508075688767
❮ Ruby Math Module