Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d
math
atan
communitycreator

What is atan() in D?

harris910

The atan() function, also called the arc tangent function, returns the inverse tangent of a number. To be more specific, it returns the inverse tangent of a number in radians.

Figure 1 shows the mathematical representation of the atan() function.

Figure 1: Mathematical representation of inverse tangent function

Note: std.math is required for this function.

To convert radians to degrees, use the following formula:

degrees = radians * ( 180.0 / PI )

Syntax

The syntax of the function is as follows:

atan(number)
//number can be real, float, or double.

Parameter

This function requires a number as a parameter.

Return value

atan() returns the inverse tangent of a number (radians) that is sent as a parameter.

The return value lies in the interval [-PI/2, PI/2] radians.

Code

The code below shows the use of the atan() function in D.

import core.stdc.stdio;
import std.stdio;
//header required for function
import std.math;

int main() {
    //positive number in radians
    writeln("The value of atan(0.5): ",atan(0.5) ," Radians");

    // negative number in radians
    writeln("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.14159265
    double result=atan(1.0) * (180.0 / PI);
    writeln("The value of atan(1.0): ",result," Degrees");

    return 0;
}

RELATED TAGS

d
math
atan
communitycreator
RELATED COURSES

View all Courses

Keep Exploring