In Swift, the atan()
function, also called the arc tangent function, is used to return the inverse tangent of a number.
Below is the mathematical representation of the atan()
function:
Note: We need to import
Foundation
in our code to use theatan()
function. We can import it like with theimport Foundation
command.
To convert radians to degrees, use the following formula:
degrees = radians * ( 180.0 / pi )
atan(number)
//number can be real, float, or double.
This function requires a number as a parameter.
This function returns the inverse tangent of a number that is sent as a parameter.
The return value lies in the interval [-PI/2, PI/2]
radians.
import Swiftimport Foundation//positive number in radiansprint("The value of atan(0.5) :", atan(0.5), "Radians");// negative number in radiansprint("The value of atan(-0.5) :", atan(-0.5), "Radians");//applying atan() and then converting the result in radians to degrees// radians = 1.0// PI = 3.14159265print("The value of atan(1.0): ",atan(1.0) * (180.0 / Double.pi)," Degrees");
Foundation
header required for the atan()
function.atan()
function to calculate the arc tangent of a positive number.atan()
function to calculate the arc tangent of a negative number.atan()
function to calculate the arc tangent of a positive number and convert the result to degrees.